Created
November 1, 2010 10:21
-
-
Save mataspetrikas/657947 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.soundcloud.player.api { | |
| import flash.events.Event; | |
| /** | |
| * @author matas | |
| */ | |
| public class PlayerAPIEvent extends Event { | |
| private var _data : Object; | |
| //onPlayerReady an event fired when the player is ready for playback | |
| public static const READY : String = 'onPlayerReady'; | |
| // onPlayerUnload should trigger when the page containing the player is closed (experimental) | |
| public static const UNLOAD : String = "onPlayerUnload"; | |
| //onMediaStart an event fired when the currently loaded song begins playback | |
| public static const START : String = 'onMediaStart'; | |
| //onMediaEnd an event fired when the currently loaded song ends playback | |
| public static const END : String = 'onMediaEnd'; | |
| //onMediaPause an event fired when the currently loaded song pause playback | |
| public static const PAUSE : String = 'onMediaPause'; | |
| //onMediaPause an event fired when the currently loaded song starts/resumes playback | |
| public static const PLAY : String = 'onMediaPlay'; | |
| //onMediaStop an event fired when the currently loaded song stops playback | |
| public static const STOP : String = 'onMediaStop'; | |
| //onMediaBuffering an event fired when the currently loaded song buffers | |
| public static const BUFFERING : String = 'onMediaBuffering'; | |
| //onMediaDoneBuffering an event fired when the currently loaded song is done buffering | |
| public static const BUFFERING_DONE : String = 'onMediaDoneBuffering'; | |
| //onPlayerError an event fired when the player couldn't load the resource from player (track removed, disabled, hidden, etc.) | |
| public static const NOT_FOUND : String = "onPlayerError"; | |
| //onMediaSeek an event fired when the user changes playing position in currently loaded song | |
| public static const SEEK : String = "onMediaSeek"; | |
| public function PlayerAPIEvent(type : String, bubbles : Boolean = true, cancelable : Boolean = false, data : Object = null) { | |
| super(type, bubbles, cancelable); | |
| _data = data; | |
| } | |
| public function get data() : Object { | |
| return _data; | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.soundcloud.player { | |
| /** | |
| * @author matas | |
| */ | |
| public interface PlayerInterface { | |
| function play() : void; | |
| function pause() : void; | |
| function seek(position : Number) : void; | |
| function skip(id : uint) : void; | |
| function load(url : String) : void; | |
| function toggle() : void; | |
| function stop() : void; | |
| function next() : void; | |
| function prev() : void; | |
| function getTrackDuration() : Number; | |
| function getTrackPosition() : Number; | |
| function getTracks() : Array; | |
| function getPlaylist() : Object; | |
| function getCurrentTrack() : Object; | |
| function getCurrentTrackIndex() : int; | |
| function setVolume(value : Number) : void; | |
| function getVolume() : Number; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.soundcloud.loader { | |
| import flash.events.MouseEvent; | |
| import com.soundcloud.player.api.PlayerAPIEvent; | |
| import flash.display.DisplayObject; | |
| import flash.display.Loader; | |
| import flash.display.Sprite; | |
| import flash.events.Event; | |
| import flash.net.URLRequest; | |
| import flash.system.Security; | |
| /* | |
| * An example of SoundCloud widget embedding in ActionScript | |
| * | |
| */ | |
| public class PlayerLoader extends Sprite { | |
| private var _playerUrl : String = "http://player.soundcloud.com/player.swf"; | |
| public function PlayerLoader() { | |
| Security.allowDomain('*'); | |
| var mLoader : Loader = new Loader(); | |
| var mRequest : URLRequest = new URLRequest(_playerUrl + "?url=http://soundcloud.com/matas/sets/lietuva&show_comments=false&default_width=450&default_height=250"); | |
| mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler); | |
| mLoader.load(mRequest); | |
| } | |
| private function onCompleteHandler(loadEvent : Event) : void { | |
| var player : DisplayObject = loadEvent.currentTarget.content; | |
| addChild(player); | |
| addEventListener(PlayerAPIEvent.READY, onReady); | |
| addEventListener(PlayerAPIEvent.BUFFERING, onBuffer); | |
| addEventListener(PlayerAPIEvent.PLAY, onPlay); | |
| trace('player height:' + player.height); | |
| trace('player width' + player.width); | |
| var onClickz : Function = function(e:MouseEvent):void{ | |
| player['load']('http://soundcloud.com/matas'); | |
| }; | |
| addEventListener(MouseEvent.CLICK, onClickz); | |
| } | |
| private function onPlay(e : Event) : void { | |
| trace('player playing') | |
| } | |
| private function onReady(e : Event) : void { | |
| trace('player ready'); | |
| e.target.play(); | |
| } | |
| private function onBuffer(e : Event) : void { | |
| trace('player buffering'); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment