Skip to main content
Participant
July 15, 2013
Question

Brightcove player issue

  • July 15, 2013
  • 0 replies
  • 791 views

Hi,

I am having problems with brightcove player in adobe Air development. I use AIR development for blackberry and I need to embed the brightcove player in the page.

the code snippet for loading the player is given by the brightcove site which is:

// By use of this code snippet, I agree to the Brightcove Publisher T&C

// found at https://accounts.brightcove.com/en/terms-and-conditions/.

package {

          import flash.display.Loader;

          import flash.display.LoaderInfo;

          import flash.display.Sprite;

          import flash.events.Event;

          import flash.events.ProgressEvent;

          import flash.net.URLRequest;

          import flash.system.ApplicationDomain;

          import flash.system.LoaderContext;

          import flash.system.SecurityDomain;

          import flash.system.Security;

                    /*

                    * To use this class to load your Brightcove player instance, save this code into the root directory

                    * of your project as BrightcovePlayer.as. Then, within your application, you can instantiate this player

                    * using the following syntax:

                    *

                    *          var player:BrightcovePlayer = new BrightcovePlayer();

                    *          addChild(player); /// must be added to a display object container, such as a Sprite instance

                    *

                    */

                    public class BrightcovePlayer extends Sprite {

                    private var bcPlayer:Object;

                    /**

                    * Constructor. Pass in different configuration parameters if you wish to reuse this snippet

                    * for other player instances. The config object passed must have a playerID, playerKey, width and height.

                    * In addition, pass isUI=true if you are using UI elements other than the VideoPlayer, isVid=true if

                    * you are using the video player or isSlim=true if you are using the VideoDisplay.

                    *

                    * var config = {};

                    * config.playerID = 12345;

                    * config.playerKey = "abcdefg1234567";

                    * config.width = 486;

                    * config.height = 412;

                    * config.isVid = true;

                    * var player:BrightcovePlayer = new BrightcovePlayer(config);

                    *

                    * @9397041 config The configuration object of parameters to use for the player.

                    */

                    public function BrightcovePlayer(config:Object=null) {

                              init(config);

                    }

                    private function init(config:Object=null):void {

                              Security.allowDomain("http://admin.brightcove.com");

                              var originalConfig:Object = {};

                              // change the playerID and playerKey to load a different player

                              originalConfig.playerID = 2540948033001;

                              originalConfig.playerKey = "AQ~~,AAACT_LLVeE~,Nd0KtlZn3RA-FR00y4ZN8kKhnwcwUeuL";

                              originalConfig.width = 480;

                              originalConfig.height = 450;

                              if (config == null) {

                                        createPlayer(originalConfig);

                              } else {

                                        var justContent:Boolean = true;

                                        for (var i:String in config) {

                                                  if (i.charAt(0) != "@") {

                                                            justContent = false;

                                                            break;

                                                  }

                                        }

                                        if (justContent) {

                                                  for (i in config) {

                                                            originalConfig = config;

                                                  }

                                                  createPlayer(originalConfig);

                                        } else {

                                                  createPlayer(config, true);

                                        }

                              }

                    }

                    private function onPlayerLoadInit(event:Event):void {

                              var loaderInfo:LoaderInfo = event.target as LoaderInfo;

                              var loader:Loader = loaderInfo.loader;

                              var player:Sprite = loaderInfo.content as Sprite;

                              if (bcPlayer && player != bcPlayer) {

                                        if (bcPlayer.parent) {

                                                  bcPlayer.parent.removeChild(bcPlayer);

                                        }

                              }

                              bcPlayer = player;

                              addChild(bcPlayer as Sprite);

                              if (contains(loader)) removeChild(loader);

                    }

                    private function onPlayerLoadProgress(event:ProgressEvent):void {

                              dispatchEvent(event);

                    }

                    private function createPlayer(config:Object, freshConfig:Boolean=false):void {

                              var cacheServerServices:String = "http://c.brightcove.com/services";

 

                              var configItems:String = "";

                              for (var i:String in config) {

                                        if (i == "width" || i == "height") continue;

                                        configItems += "&" + i + "=" + escape(config);

                              }

                              var file:String = cacheServerServices + "/viewer/federated_f9?" +

                                        "&playerWidth="+escape(config["width"])+

                                        "&playerHeight="+escape(config["height"])+

                                        "&dynamicStreaming=true"+

                                        configItems;

                              if (!freshConfig) {

                                        file += "&isVid=1&isUI=1";

                              }

                              var player:Loader = new Loader();

                              addChild(player);

                              player.contentLoaderInfo.addEventListener(Event.INIT, onPlayerLoadInit);

                              player.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onPlayerLoadProgress);

                              var context:LoaderContext = new LoaderContext();

                              context.applicationDomain = ApplicationDomain.currentDomain;

                              player.load(new URLRequest(file), context);

                    }

                    public function onTemplateLoaded():void {

                              dispatchEvent(new Event("templateLoaded"));

                    }

                    public function getModule(module:String):Object {

                              return Object(bcPlayer).getModule(module);

                    }

          }

}

and I comment out the line:

Security.allowDomain("http://admin.brightcove.com");

becayse it throws security sandbox exception, so after removing the line it seems to load the player but when it tries to add it to the stage it throws the exception:

SecurityError: Error #2047: Security sandbox violation: parent: http://admin.brightcove.com/viewer/us20130702.1553/federatedVideoUI/BrightcovePlayer.swf?uid=1373901121092 cannot access app:/MyApp.swf.

          at flash.display::DisplayObject/get parent()

can anyone help me with this problem ?

This topic has been closed for replies.