source: trunk/fl5/src/com/longtailvideo/jwplayer/player/Player.as @ 299

Revision 299, 4.5 KB checked in by pablo, 4 years ago (diff)

Stringing together MVC model

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