source: trunk/as3/com/jeroenwijering/player/Player.as @ 157

Revision 157, 4.4 KB checked in by jeroen, 4 years ago (diff)

added a variable for respecting the duration and fixed a stall-on-repeat bug in http

  • Property svn:executable set to *
  • Property svn:keywords set to Rev
Line 
1/**
2* Player that crunches through all media formats Flash can read.
3**/
4package com.jeroenwijering.player {
5
6
7import com.jeroenwijering.events.*;
8import com.jeroenwijering.models.*;
9import com.jeroenwijering.plugins.*;
10import com.jeroenwijering.utils.Configger;
11
12import flash.display.MovieClip;
13import flash.events.Event;
14
15
16public class Player extends MovieClip {
17
18
19        /** All configuration values. Change them to hard-code your preferences. **/
20        public var config:Object = {
21                author:undefined,
22                description:undefined,
23                date:undefined,
24                duration:0,
25                file:undefined,
26                image:undefined,
27                link:undefined,
28                start:0,
29                streamer:undefined,
30                tags:undefined,
31                title:undefined,
32                type:undefined,
33
34                backcolor:undefined,
35                frontcolor:undefined,
36                lightcolor:undefined,
37                screencolor:undefined,
38
39                controlbar:'bottom',
40                height:300,
41                playlist:'none',
42                playlistsize:180,
43                skin:undefined,
44                width:400,
45
46                autostart:false,
47                bufferlength:1,
48                displayclick:'play',
49                fullscreen:false,
50                icons:true,
51                item:0,
52                logo:undefined,
53                mute:false,
54                repeat:'none',
55                resizing:true,
56                respectduration:false,
57                shuffle:false,
58                smoothing:true,
59                state:'IDLE',
60                stretching:'uniform',
61                volume:90,
62
63                abouttext:undefined,
64                aboutlink:"http://www.longtailvideo.com/players/jw-flv-player/",
65                client:undefined,
66                id:undefined,
67                linktarget:'_blank',
68                plugins:undefined,
69                token:undefined,
70                tracecall:undefined,
71                version:'4.4.155'
72        };
73        /** Base directory from which all plugins are loaded. **/
74        public var basedir:String = 'http://plugins.longtailvideo.com/';
75        /** Reference to all stage graphics. **/
76        public var skin:MovieClip;
77        /** Reference to the View of the MVC cycle, defining all API calls. **/
78        public var view:View;
79        /** Object that loads all configuration variables. **/
80        protected var configger:Configger;
81        /** Object that load the skin and plugins. **/
82        protected var sploader:SPLoader;
83        /** Reference to the Controller of the MVC cycle. **/
84        protected var controller:Controller;
85        /** Reference to the model of the MVC cycle. **/
86        protected var model:Model;
87
88
89        /** Constructor; hides player and waits until it is added to the stage. **/
90        public function Player():void {
91                visible = false;
92                skin = this['player'];
93                addEventListener(Event.ADDED_TO_STAGE,loadConfig);
94        };
95
96
97        /** When added to stage, the player loads configuration settings. **/
98        protected function loadConfig(evt:Event=null):void {
99                configger = new Configger(this);
100                configger.addEventListener(Event.COMPLETE,loadSkin);
101                configger.load(config);
102        };
103
104
105        /** When config is loaded, the player laods the skin. **/
106        protected function loadSkin(evt:Event=null):void {
107                sploader = new SPLoader(this);
108                sploader.addEventListener(SPLoaderEvent.SKIN,loadMVC);
109                sploader.loadSkin();
110        };
111
112
113        /** When the skin is loaded, the model/view/controller are inited. **/
114        protected function loadMVC(evt:SPLoaderEvent=null):void {
115                controller = new Controller(config,skin,sploader);
116                model = new Model(config,skin,sploader,controller);
117                view = new View(config,skin,sploader,controller,model);
118                controller.closeMVC(model,view);
119                loadModels();
120                loadPlugins();
121                sploader.addEventListener(SPLoaderEvent.PLUGINS,startPlayer);
122                sploader.loadPlugins();
123        };
124
125
126        /** Initialize all playback models. **/
127        protected function loadModels():void {
128                model.loadModel(new CameraModel(model),'camera');
129                model.loadModel(new HTTPModel(model),'http');
130                model.loadModel(new ImageModel(model),'image');
131                model.loadModel(new LighttpdModel(model),'lighttpd');
132                model.loadModel(new NginxModel(model),'nginx');
133                model.loadModel(new RTMPModel(model),'rtmp');
134                model.loadModel(new SoundModel(model),'sound');
135                model.loadModel(new VideoModel(model),'video');
136                model.loadModel(new YoutubeModel(model),'youtube');
137        };
138
139
140        /** Init built-in plugins and load external ones. **/
141        protected function loadPlugins():void {
142                sploader.addPlugin(new Display(),'display');
143                sploader.addPlugin(new Rightclick(),'rightclick');
144                sploader.addPlugin(new Controlbar(),'controlbar');
145                sploader.addPlugin(new Playlist(),'playlist');
146        };
147
148
149        /**
150        * Everything is now ready. The Player is redrawn, shown and the file is loaded.
151        *
152        * The Player broadcasts a READY event here to actionscript.
153        * The View will send an asynchroneous PlayerReady event to javascript.
154        **/
155        protected function startPlayer(evt:SPLoaderEvent=null) {
156                view.sendEvent(ViewEvent.REDRAW);
157                visible = true;
158                dispatchEvent(new PlayerEvent(PlayerEvent.READY));
159                view.playerReady();
160                if(config['file']) {
161                        view.sendEvent(ViewEvent.LOAD,config);
162                }
163        };
164
165
166}
167
168
169}
Note: See TracBrowser for help on using the repository browser.