| 1 | package com.longtailvideo.jwplayer.player { |
|---|
| 2 | import com.longtailvideo.jwplayer.controller.Controller; |
|---|
| 3 | import com.longtailvideo.jwplayer.events.PlayerEvent; |
|---|
| 4 | import com.longtailvideo.jwplayer.model.Model; |
|---|
| 5 | import com.longtailvideo.jwplayer.model.PlayerConfig; |
|---|
| 6 | import com.longtailvideo.jwplayer.model.Playlist; |
|---|
| 7 | import com.longtailvideo.jwplayer.plugins.IPlugin; |
|---|
| 8 | import com.longtailvideo.jwplayer.view.ISkin; |
|---|
| 9 | import com.longtailvideo.jwplayer.view.PlayerComponents; |
|---|
| 10 | import com.longtailvideo.jwplayer.view.View; |
|---|
| 11 | |
|---|
| 12 | import flash.display.Sprite; |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | /** |
|---|
| 16 | * Sent when the player has been initialized and skins and plugins have been successfully loaded. |
|---|
| 17 | * |
|---|
| 18 | * @eventType com.longtailvideo.jwplayer.events.PlayerEvent.JWPLAYER_READY |
|---|
| 19 | */ |
|---|
| 20 | [Event(name="jwplayerReady", type = "com.longtailvideo.jwplayer.events.PlayerEvent")] |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | /** |
|---|
| 24 | * Main class for JW Flash Media Player |
|---|
| 25 | * |
|---|
| 26 | * @author Pablo Schklowsky |
|---|
| 27 | */ |
|---|
| 28 | public class Player extends Sprite { |
|---|
| 29 | private static var playerVersion:String = "5.0.1"; |
|---|
| 30 | |
|---|
| 31 | private var model:Model; |
|---|
| 32 | private var view:View; |
|---|
| 33 | private var controller:Controller; |
|---|
| 34 | |
|---|
| 35 | /** Player constructor **/ |
|---|
| 36 | public function Player() { |
|---|
| 37 | model = new Model(); |
|---|
| 38 | view = new View(this); |
|---|
| 39 | controller = new Controller(this, model, view); |
|---|
| 40 | |
|---|
| 41 | model.addGlobalListener(forward); |
|---|
| 42 | view.addGlobalListener(forward); |
|---|
| 43 | controller.addGlobalListener(forward); |
|---|
| 44 | |
|---|
| 45 | // Initialize V4 "simulator" singleton |
|---|
| 46 | new PlayerV4Emulation(this); |
|---|
| 47 | |
|---|
| 48 | controller.setupPlayer(); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | /** |
|---|
| 52 | * Forwards all MVC events to interested listeners. |
|---|
| 53 | * @param evt |
|---|
| 54 | */ |
|---|
| 55 | protected function forward(evt:PlayerEvent):void { |
|---|
| 56 | dispatchEvent(evt); |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | /** |
|---|
| 60 | * The player's current configuration |
|---|
| 61 | */ |
|---|
| 62 | public function get config():PlayerConfig { |
|---|
| 63 | return model.config; |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | /** |
|---|
| 67 | * Player version getter |
|---|
| 68 | */ |
|---|
| 69 | public static function get version():String { |
|---|
| 70 | return playerVersion; |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | /** |
|---|
| 74 | * Reference to player's skin. If no skin has been loaded, returns null. |
|---|
| 75 | */ |
|---|
| 76 | public function get skin():ISkin { |
|---|
| 77 | return view.skin; |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | /** |
|---|
| 81 | * The current player state |
|---|
| 82 | */ |
|---|
| 83 | public function get state():String { |
|---|
| 84 | return model.state; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | /** |
|---|
| 88 | * The player's playlist |
|---|
| 89 | */ |
|---|
| 90 | public function get playlist():Playlist { |
|---|
| 91 | return model.playlist; |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | /** |
|---|
| 95 | * Set to true when the player is blocking playback. |
|---|
| 96 | */ |
|---|
| 97 | public function get isBlocking():Boolean { |
|---|
| 98 | return controller.blocking; |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | /** |
|---|
| 102 | * Request that the player block playback. When the Player is blocking, the currently playing stream is |
|---|
| 103 | * paused, and no new playback-related commands will be honored until <code>unblockPlayback</code> is |
|---|
| 104 | * called. |
|---|
| 105 | * |
|---|
| 106 | * @param target Reference to plugin requesting playback blocking |
|---|
| 107 | * @return <code>true</code>, if the blocking request is successful. If another plugin is blocking,returns |
|---|
| 108 | * <code>false</code>. |
|---|
| 109 | */ |
|---|
| 110 | public function blockPlayback(target:IPlugin):Boolean { |
|---|
| 111 | return controller.blockPlayback(target); |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | /** |
|---|
| 115 | * Unblocks the player. If the player was buffering or playing when it was blocked, playback will resume. |
|---|
| 116 | * |
|---|
| 117 | * @param target Reference to the requesting plugin. |
|---|
| 118 | * @return <code>true</code>, if <code>target</code> had previously requested player blocking. |
|---|
| 119 | * |
|---|
| 120 | */ |
|---|
| 121 | public function unblockPlayback(target:IPlugin):Boolean { |
|---|
| 122 | return controller.unblockPlayback(target); |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | public function volume(volume:Number):Boolean { |
|---|
| 126 | return controller.setVolume(volume); |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | public function mute(state:Boolean):Boolean { |
|---|
| 130 | return controller.mute(state); |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | public function play():Boolean { |
|---|
| 134 | return controller.play(); |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | public function pause():Boolean { |
|---|
| 138 | return controller.pause(); |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | public function stop():Boolean { |
|---|
| 142 | return controller.stop(); |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | public function seek(position:Number):Boolean { |
|---|
| 146 | return controller.seek(position); |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | public function load(item:*):Boolean { |
|---|
| 150 | return controller.load(item); |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | public function playlistItem(index:Number):Boolean { |
|---|
| 154 | return controller.load(index); |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | public function playlistNext():Boolean { |
|---|
| 158 | return controller.load(model.playlist.currentIndex+1); |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | public function playlistPrev():Boolean { |
|---|
| 162 | return controller.load(model.playlist.currentIndex-1); |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | /** Force a redraw of the player **/ |
|---|
| 166 | public function redraw():Boolean { |
|---|
| 167 | return controller.redraw(); |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | public function fullscreen(on:Boolean):Boolean { |
|---|
| 171 | return controller.fullscreen(on); |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | public function link(index:Number=NaN):Boolean { |
|---|
| 175 | return controller.link(index); |
|---|
| 176 | } |
|---|
| 177 | |
|---|
| 178 | public function get uiComponents():PlayerComponents { |
|---|
| 179 | return view.components; |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | } |
|---|
| 183 | } |
|---|