OSMF开源播放器源码解读

来源:互联网 发布:手工编程的步骤 编辑:程序博客网 时间:2024/05/17 02:15
在sourceforge下载源码http://sourceforge.net/projects/osmf.adobe/files/在OSMF\player\StrobeMediaPlayback是一个播放器,可以拿过来改改用。。。首先看一下执行的流程。查看StrobeMediaPlayback.as类,该类继承Sprite。1.public function StrobeMediaPlayback() 构造函数,在构造函数中添加了一个事件addEventListener(Event.ADDED_TO_STAGE, onAddedToStage)。2.private function onAddedToStage(event:Event):void 在该事件中调用了初始化方法initialize。3.public function initialize(parameters:Object, stage:Stage, loaderInfo:LoaderInfo, pluginHostWhitelist:Array):void 方法的参数哪来的我还不知道。。。
public function initialize(parameters:Object, stage:Stage, loaderInfo:LoaderInfo, pluginHostWhitelist:Array):void{removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);// Keep a reference to the stage (when a preloader is used, the// local stage property is null at this time):if (stage != null){_stage = stage;}// Keep a reference to the stage (when a preloader is used, the// local stage property is null at this time):if (loaderInfo != null){_loaderInfo = loaderInfo;}this.pluginHostWhitelist = new Vector.<String>();if (pluginHostWhitelist){for each(var pluginHost:String in pluginHostWhitelist){this.pluginHostWhitelist.push(pluginHost);}// Add the current domain only if the pluginHostWhitelist != null // (since for null we want to disable the whitelist protection).var currentDomain:String = StrobeUtils.retrieveHostNameFromUrl(loaderInfo.loaderURL);this.pluginHostWhitelist.push(currentDomain);}//CONFIG::FLASH_10_1{//Register the global error handler.if (_loaderInfo != null && _loaderInfo.hasOwnProperty("uncaughtErrorEvents")){_loaderInfo["uncaughtErrorEvents"].addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onUncaughtError);}}var assetManager:AssetsManager = new AssetsManager();_injector = new InjectorModule();var configurationLoader:ConfigurationLoader = _injector.getInstance(ConfigurationLoader);configurationLoader.addEventListener(Event.COMPLETE, onConfigurationReady);configuration = _injector.getInstance(PlayerConfiguration);player = _injector.getInstance(MediaPlayer);player.addEventListener(TimeEvent.COMPLETE, onComplete);player.addEventListener(MediaErrorEvent.MEDIA_ERROR, onMediaError);// Add DRM error handlervar drmManager:DRMManager = DRMManager.getDRMManager();drmManager.addEventListener(DRMErrorEvent.DRM_ERROR, onDRMError);// this is used for DVR rolling window// TODO: Add this event only when the resource is DVR rolling window not all the timeplayer.addEventListener(TimeEvent.CURRENT_TIME_CHANGE, onCurrentTimeChange);configurationLoader.load(parameters, configuration);function onConfigurationReady(event:Event):void{OSMFSettings.enableStageVideo = configuration.enableStageVideo;//CONFIG::LOGGING//{//logger.trackObject("PlayerConfiguration", configuration);//}if (configuration.skin != null && configuration.skin != ""){var skinLoader:XMLFileLoader = new XMLFileLoader();skinLoader.addEventListener(IOErrorEvent.IO_ERROR, onSkinLoaderFailure);skinLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSkinLoaderFailure);skinLoader.addEventListener(Event.COMPLETE, onSkinLoaderComplete);skinLoader.load(configuration.skin);}else{onSkinLoaderComplete();}}function onSkinLoaderComplete(event:Event = null):void{if (event != null){var skinLoader:XMLFileLoader = event.target as XMLFileLoader;var skinParser:SkinParser = new SkinParser();skinParser.parse(skinLoader.xml, assetManager);}var chromeProvider:ChromeProvider = ChromeProvider.getInstance();chromeProvider.addEventListener(Event.COMPLETE, onChromeProviderComplete);if (chromeProvider.loaded == false && chromeProvider.loading == false){chromeProvider.load(assetManager);}else{onChromeProviderComplete();}}function onSkinLoaderFailure(event:Event):void{trace("WARNING: failed to load skin file at " + configuration.skin);onSkinLoaderComplete();}if (configuration.javascriptCallbackFunction != "" && ExternalInterface.available && mediaPlayerJSBridge == null){mediaPlayerJSBridge = new JavaScriptBridge(this, player, StrobeMediaPlayer, configuration.javascriptCallbackFunction);}}
用到了InjectorModule对象,在初始化这个对象的时候内部还实例化了一些其他对象,例如configurationLoader,configuration,player,通过injector.getInstance(XXX)就可以得到,具体可以看InjectorModule的源码。得到configurationLoader,给他一个事件configurationLoader.addEventListener(Event.COMPLETE, onConfigurationReady);给play添加3个事件,player.addEventListener(TimeEvent.COMPLETE, onComplete);player.addEventListener(MediaErrorEvent.MEDIA_ERROR, onMediaError);player.addEventListener(TimeEvent.CURRENT_TIME_CHANGE, onCurrentTimeChange);使用configurationLoader加载parameters的资源,加载之后可以通过configuration得到。4.function onConfigurationReady(event:Event):void 这个方法是第三步给configurationLoader添加的事件,在调用load方法加载资源后会调用这个方法。在这个中新建了一个XMLFileLoader,如果configuration.skin不是空,就用XMLFileLoader加载资源,加载完调用onSkinLoaderComplete事件,如果是空,就直接调用onSkinLoaderComplete事件。最后实例化一个JavaScriptBridge类。5.function onSkinLoaderComplete(event:Event = null):void解析xml文件。得到ChromeProvider对象,如果状态不是正在加载也不是已经加载完毕,就加载assetManager,并且添加onChromeProviderComplete事件。6.private function onChromeProviderComplete(event:Event = null):void第一步就调用initializeView,顾名思义,开始把播放器的样子展现出来。
0 0
原创粉丝点击