02-22-2012 05:55 AM
i'm trying to built a sample component using BEML and the SWFLoader. The BEML I'm using is derived from the Video Player template:
<Runtime> <Theme name="Deluxe" style="Light"/> <Layout> <VBox> <VideoPlayer id="videoPlayer" width="486" height="412" depth="1"/> <SWFLoader source="http://localhost/sandbox/plugin.swf" depth="2"/> </VBox> </Layout> </Runtime>
The plugin swf is very basic -- only to test out the Player API:
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="onInitialize()" > <mx:Script> <![CDATA[ private var _player:Object; private function onInitialize():void { Security.allowDomain("*"); } public function setInterface(player:Object):void { _player = player; _player.addEventListener("templateLoaded", onTemplateLoaded); var exp:Object = _player.getModule("experience"); if (exp) { exp.addEventListener("templateLoaded", onTemplateLoaded); } } private function onTemplateLoaded(event:Event):void { trace(event); } ]]> </mx:Script> </mx:Application>
The issue I'm running into here is that _player.getModule("experience") returns nothing. I'm not sure if this is because the BEML template is barebones. I've also cycled through all the modules for the _player and it only returns a valid object for "videoPlayer". However, sometimes when I try to attach listeners to the video module, it throws an RTE. What am I doing wrong?
Solved! Go to Solution.
02-28-2012 10:17 AM
I believe the modules are not ready to be accessed. You can call getModules and then check the status of the tempalte before accessing the modules. Here are some examples on how to do it:
http://support.brightcove.com/en/docs/creating-cus
02-28-2012 11:35 AM
I also noticed that you are using Flex, this is some sample code using Flex 4.5 with a Brightcove Player:
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:bc="com.brightcove.api.*" creationComplete="initBrightcovePlayer()" minWidth="955" minHeight="600"> <fx:Declarations> <!-- Place non-visual elements (e.g., services, value objects) here --> </fx:Declarations> <fx:Script> <![CDATA[ import com.brightcove.api.APIModules; import com.brightcove.api.BrightcoveFlexComponent; import com.brightcove.api.events.ExperienceEvent; import com.brightcove.api.modules.ExperienceModule; import com.brightcove.api.modules.VideoPlayerModule; import com.sample.BrightcovePlayer; import spark.components.Button; private var _bcPlayer:BrightcovePlayer; private var _playerFlexWrapper:BrightcoveFlexComponent = new BrightcoveFlexComponent(); public function initBrightcovePlayer():void { _playerFlexWrapper.playerClass = BrightcovePlayer; _playerFlexWrapper.width = 486; _playerFlexWrapper.height = 412; _playerFlexWrapper.addEventListener(ExperienceEvent.TEMPLATE_LOADED, onTemplateLoaded); bcPlayerContainer.addElement(_playerFlexWrapper); } private function onTemplateLoaded(event:ExperienceEvent):void { var module:ExperienceModule = _playerFlexWrapper.getModule(APIModules.EXPERIENCE ) as ExperienceModule ; module.addEventListener(ExperienceEvent.TEMPLATE_R EADY, onTemplateReady); } private function onTemplateReady(event:ExperienceEvent):void { var videoPlayerModule:VideoPlayerModule = _playerFlexWrapper.getModule(APIModules.VIDEO_PLAY ER) as VideoPlayerModule; videoPlayerModule.loadVideo(601206666001); } ]]> </fx:Script> <s:VGroup id="bcPlayerContainer" creationComplete="initBrightcovePlayer()" > </s:VGroup> </s:Application>
