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

Revision 104, 4.1 KB checked in by jeroen, 5 years ago (diff)

added HD switch plugin (and fixed a bug in the LOAD event

  • 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.player.*;
9import com.jeroenwijering.plugins.*;
10import com.jeroenwijering.utils.Configger;
11import flash.display.MovieClip;
12import flash.events.Event;
13
14
15public class Player extends MovieClip {
16
17
18        /** All configuration values. Change them to hard-code your preferences. **/
19        public var config:Object = {
20                author:undefined,
21                description:undefined,
22                date:undefined,
23                duration:0,
24                file:undefined,
25                image:undefined,
26                link:undefined,
27                start:0,
28                tags:undefined,
29                title:undefined,
30                type:undefined,
31
32                backcolor:undefined,
33                frontcolor:undefined,
34                lightcolor:undefined,
35                screencolor:undefined,
36
37                controlbar:'bottom',
38                controlbarsize:20,
39                height:300,
40                playlist:'none',
41                playlistsize:180,
42                skin:undefined,
43                width:400,
44
45                autostart:false,
46                bufferlength:1,
47                displayclick:'play',
48                icons:true,
49                item:0,
50                logo:undefined,
51                mute:false,
52                quality:true,
53                repeat:'none',
54                resizing:true,
55                shuffle:false,
56                state:'IDLE',
57                stretching:'uniform',
58                volume:90,
59
60                abouttext:undefined,
61                aboutlink:"http://www.jeroenwijering.com/?item=JW_FLV_Player",
62                client:undefined,
63                id:undefined,
64                linktarget:'_blank',
65                plugins:undefined,
66                streamer:undefined,
67                token:undefined,
68                tracecall:undefined,
69                version:'4.3.103'
70        };
71        /** Reference to all stage graphics. **/
72        public var skin:MovieClip;
73        /** Reference to the View of the MVC cycle, which defines all API calls. **/
74        public var view:View;
75        /** Object that loads all configuration variables. **/
76        protected var configger:Configger;
77        /** Base directory from which all plugins are loaded. **/
78        protected var basedir:String = "http://plugins.longtailvideo.com/";
79        /** Object that load the skin and plugins. **/
80        protected var loader:SPLoader;
81        /** Reference to the Controller of the MVC cycle. **/
82        protected var controller:Controller;
83        /** Reference to the model of the MVC cycle. **/
84        protected var model:Model;
85
86
87        /**
88        * Constructor; initializes and starts the player.
89        *
90        * ADDED_TO_STAGE is needed when the player is loaded in Flex/Flash.
91        * Otherwise the external flashvars and the stage aren't available yet.
92        **/
93        public function Player():void {
94                visible = false;
95                skin = this['player'];
96                addEventListener(Event.ADDED_TO_STAGE,loadConfig);
97        };
98
99
100        /** When added to stage, the player loads configuration settings. **/
101        protected function loadConfig(evt:Event=null):void {
102                configger = new Configger(this);
103                configger.addEventListener(Event.COMPLETE,loadSkin);
104                configger.load(config);
105        };
106
107
108        /** Config loading completed; now load the skin. **/
109        protected function loadSkin(evt:Event=null):void {
110                loader = new SPLoader(this,basedir);
111                loader.addEventListener(SPLoaderEvent.SKIN,loadMVC);
112                loader.loadSkin(config['skin']);
113        };
114
115
116        /** Skin loading completed, now load MVC. **/
117        protected function loadMVC(evt:SPLoaderEvent=null):void {
118                controller = new Controller(config,skin);
119                model = new Model(config,skin,controller);
120                view = new View(config,skin,controller,model,loader);
121                controller.closeMVC(model,view);
122                loadPlugins();
123        };
124
125
126        /**
127        * MVC inited; now load plugins.
128        *
129        * Built-in plugins are instantiated here. External plugins are loaded.
130        * The controlbar is inited last, so it is show on top of all plugins.
131        **/
132        protected function loadPlugins():void {
133                new Rightclick().initializePlugin(view);
134                new Display().initializePlugin(view);
135                new Playlist().initializePlugin(view);
136                loader.addEventListener(SPLoaderEvent.PLUGINS,startPlayer);
137                loader.loadPlugins(config['plugins']);
138                new Controlbar().initializePlugin(view);
139        };
140
141
142        /**
143        * Everything is now loaded. The Player is redrawn, shown and the file is loaded.
144        *
145        * The Player broadcasts a READY event here to actionscript.
146        * The View will send a separate PlayerReady event to javascript.
147        **/
148        protected function startPlayer(evt:SPLoaderEvent=null) {
149                loader.removeEventListener(SPLoaderEvent.PLUGINS,startPlayer);
150                view.sendEvent(ViewEvent.REDRAW);
151                visible = true;
152                dispatchEvent(new PlayerEvent(PlayerEvent.READY));
153                if(config['file']) {
154                        view.sendEvent(ViewEvent.LOAD,config);
155                }
156        };
157
158}
159
160
161}
Note: See TracBrowser for help on using the repository browser.