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

Revision 183, 4.7 KB checked in by jeroen, 4 years ago (diff)

added livestream plugin, fixed YT stretching and added reloading of plugins to testing

  • Property svn:executable set to *
  • Property svn:keywords set to Rev
RevLine 
[132]1/**
2* Player that crunches through all media formats Flash can read.
3**/
4package com.jeroenwijering.player {
5
6
7import com.jeroenwijering.events.*;
[136]8import com.jeroenwijering.models.*;
[132]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,
[161]22                date:undefined,
[135]23                description:undefined,
[132]24                duration:0,
25                file:undefined,
26                image:undefined,
27                link:undefined,
28                start:0,
[168]29                streamer:undefined,
[132]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,
[168]54                replace:undefined,
[162]55                repeat:'none',
[132]56                resizing:true,
[157]57                respectduration:false,
[132]58                shuffle:false,
[135]59                smoothing:true,
[132]60                state:'IDLE',
61                stretching:'uniform',
62                volume:90,
[135]63
[132]64                abouttext:undefined,
65                aboutlink:"http://www.longtailvideo.com/players/jw-flv-player/",
66                client:undefined,
67                id:undefined,
68                linktarget:'_blank',
69                plugins:undefined,
70                token:undefined,
[183]71                tracecall:undefined,
72                version:'4.4.182'
[132]73        };
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                skin = this['player'];
[161]91                for(var i:Number=0; i<skin.numChildren; i++) {
92                        skin.getChildAt(i).visible = false;
93                }
[183]94                // This event is useful for Flex, but not recognized by FP9.0.16
95                try {
96                        addEventListener(Event.ADDED_TO_STAGE,loadConfig);
97                } catch(err:Error) { loadConfig(); }
[132]98        };
99
100
101        /** When added to stage, the player loads configuration settings. **/
[138]102        protected function loadConfig(evt:Event=null):void {
[132]103                configger = new Configger(this);
104                configger.addEventListener(Event.COMPLETE,loadSkin);
105                configger.load(config);
106        };
107
108
109        /** When config is loaded, the player laods the skin. **/
110        protected function loadSkin(evt:Event=null):void {
111                sploader = new SPLoader(this);
112                sploader.addEventListener(SPLoaderEvent.SKIN,loadMVC);
113                sploader.loadSkin();
114        };
115
116
117        /** When the skin is loaded, the model/view/controller are inited. **/
118        protected function loadMVC(evt:SPLoaderEvent=null):void {
119                controller = new Controller(config,skin,sploader);
120                model = new Model(config,skin,sploader,controller);
121                view = new View(config,skin,sploader,controller,model);
122                controller.closeMVC(model,view);
[161]123                addModels();
124                addPlugins();
[137]125                sploader.addEventListener(SPLoaderEvent.PLUGINS,startPlayer);
126                sploader.loadPlugins();
[132]127        };
128
129
[136]130        /** Initialize all playback models. **/
[161]131        protected function addModels():void {
132                model.addModel(new HTTPModel(model),'http');
133                model.addModel(new ImageModel(model),'image');
134                model.addModel(new RTMPModel(model),'rtmp');
135                model.addModel(new SoundModel(model),'sound');
136                model.addModel(new VideoModel(model),'video');
137                model.addModel(new YoutubeModel(model),'youtube');
[170]138
[175]139                model.addModel(new CameraModel(model),'camera');
[170]140                model.addModel(new LighttpdModel(model),'lighttpd');
141                model.addModel(new NginxModel(model),'nginx');
142                model.addModel(new BitgravityModel(model),'bitgravity');
143                model.addModel(new HighwindsModel(model),'highwinds');
144                model.addModel(new FLVSeekModel(model),'flvseek');
[136]145        };
146
147
148        /** Init built-in plugins and load external ones. **/
[161]149        protected function addPlugins():void {
[132]150                sploader.addPlugin(new Display(),'display');
151                sploader.addPlugin(new Rightclick(),'rightclick');
[170]152                sploader.addPlugin(new Controlbar(),'controlbar');
153                sploader.addPlugin(new Playlist(),'playlist');
[132]154        };
155
156
157        /**
158        * Everything is now ready. The Player is redrawn, shown and the file is loaded.
159        *
160        * The Player broadcasts a READY event here to actionscript.
161        * The View will send an asynchroneous PlayerReady event to javascript.
162        **/
163        protected function startPlayer(evt:SPLoaderEvent=null) {
164                view.sendEvent(ViewEvent.REDRAW);
165                dispatchEvent(new PlayerEvent(PlayerEvent.READY));
166                view.playerReady();
167                if(config['file']) {
168                        view.sendEvent(ViewEvent.LOAD,config);
169                }
170        };
171
172
173}
174
175
[173]176}
Note: See TracBrowser for help on using the repository browser.