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

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

fixed repeating issue with video playback

  • 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:'list',
55                resizing:true,
56                shuffle:false,
57                smoothing:true,
58                state:'IDLE',
59                stretching:'uniform',
60                volume:90,
61
62                abouttext:undefined,
63                aboutlink:"http://www.longtailvideo.com/players/jw-flv-player/",
64                client:undefined,
65                id:undefined,
66                linktarget:'_blank',
67                plugins:undefined,
68                token:undefined,
69                tracecall:undefined,
70                version:'4.4.153'
71        };
72        /** Base directory from which all plugins are loaded. **/
73        public var basedir:String = 'http://plugins.longtailvideo.com/';
74        /** Reference to all stage graphics. **/
75        public var skin:MovieClip;
76        /** Reference to the View of the MVC cycle, defining all API calls. **/
77        public var view:View;
78        /** Object that loads all configuration variables. **/
79        protected var configger:Configger;
80        /** Object that load the skin and plugins. **/
81        protected var sploader:SPLoader;
82        /** Reference to the Controller of the MVC cycle. **/
83        protected var controller:Controller;
84        /** Reference to the model of the MVC cycle. **/
85        protected var model:Model;
86
87
88        /** Constructor; hides player and waits until it is added to the stage. **/
89        public function Player():void {
90                visible = false;
91                skin = this['player'];
92                addEventListener(Event.ADDED_TO_STAGE,loadConfig);
93        };
94
95
96        /** When added to stage, the player loads configuration settings. **/
97        protected function loadConfig(evt:Event=null):void {
98                configger = new Configger(this);
99                configger.addEventListener(Event.COMPLETE,loadSkin);
100                configger.load(config);
101        };
102
103
104        /** When config is loaded, the player laods the skin. **/
105        protected function loadSkin(evt:Event=null):void {
106                sploader = new SPLoader(this);
107                sploader.addEventListener(SPLoaderEvent.SKIN,loadMVC);
108                sploader.loadSkin();
109        };
110
111
112        /** When the skin is loaded, the model/view/controller are inited. **/
113        protected function loadMVC(evt:SPLoaderEvent=null):void {
114                controller = new Controller(config,skin,sploader);
115                model = new Model(config,skin,sploader,controller);
116                view = new View(config,skin,sploader,controller,model);
117                controller.closeMVC(model,view);
118                loadModels();
119                loadPlugins();
120                sploader.addEventListener(SPLoaderEvent.PLUGINS,startPlayer);
121                sploader.loadPlugins();
122        };
123
124
125        /** Initialize all playback models. **/
126        protected function loadModels():void {
127                model.loadModel(new CameraModel(model),'camera');
128                model.loadModel(new HTTPModel(model),'http');
129                model.loadModel(new ImageModel(model),'image');
130                model.loadModel(new LighttpdModel(model),'lighttpd');
131                model.loadModel(new NginxModel(model),'nginx');
132                model.loadModel(new RTMPModel(model),'rtmp');
133                model.loadModel(new SoundModel(model),'sound');
134                model.loadModel(new VideoModel(model),'video');
135                model.loadModel(new YoutubeModel(model),'youtube');
136        };
137
138
139        /** Init built-in plugins and load external ones. **/
140        protected function loadPlugins():void {
141                sploader.addPlugin(new Display(),'display');
142                sploader.addPlugin(new Rightclick(),'rightclick');
143                sploader.addPlugin(new Controlbar(),'controlbar');
144                sploader.addPlugin(new Playlist(),'playlist');
145        };
146
147
148        /**
149        * Everything is now ready. The Player is redrawn, shown and the file is loaded.
150        *
151        * The Player broadcasts a READY event here to actionscript.
152        * The View will send an asynchroneous PlayerReady event to javascript.
153        **/
154        protected function startPlayer(evt:SPLoaderEvent=null) {
155                view.sendEvent(ViewEvent.REDRAW);
156                visible = true;
157                dispatchEvent(new PlayerEvent(PlayerEvent.READY));
158                view.playerReady();
159                if(config['file']) {
160                        view.sendEvent(ViewEvent.LOAD,config);
161                }
162        };
163
164
165}
166
167
168}
Note: See TracBrowser for help on using the repository browser.