2

如指南所示(如下),我正在使用 Brightcove api,但我的问题是我无法以这种方式管理两个玩家,我需要它:

<object id="VideoBrightcove?c=4&m=2&s=2" class="BrightcoveExperience">
  <param name="bgcolor" value="#FFFFFF" />
  <param name="width" value="480" />
  <param name="height" value="270" />
  <param name="playerID" value="2549948545001" />
  <param name="playerKey" value="AQ~~,AAABmA9XpXk~,-Kp7jNgisreVadKjzdyJfLcfukyXcGqB" />
  <param name="isVid" value="true" />
  <param name="isUI" value="true" />
  <param name="dynamicStreaming" value="true" />
  <param name="includeAPI" value="true" />
  <param name="templateLoadHandler" value="BCLS.onTemplateLoad" />
  <param name="templateReadyHandler" value="BCLS.onTemplateReady">
  <param name="@videoPlayer" value="1754261637001" />
</object>

<script>
    var BCLS = (function() {
        var player,APIModules,mediaEvent,videoPlayer;
        return {
            onTemplateLoad : function (experienceID) { 
                //do something
            },
            onTemplateReady : function (evt) { 
                //do something
            },
            onProgress : function (evt) {
                //do something
            },
            onBegin : function (evt) {
                //do something
            },
            onComplete : function (evt) {
                //do something
            }
        }
    }());
</script>

有管理多个玩家的想法吗?

4

1 回答 1

2

A lot of the code samples you'll for using the Smart Player API use global variables, or as I assume you're doing, BCLS.player for the "experience", BCLS.videoPlayer for the video player module and so on. That won't work well with multiple players unless you maintain a separate set of load/ready handler functions and a separate set of variables for each player. That won't scale well.

The easiest way to work with multiple players is to rely on the event passed to the event handler as this includes the player id at event.target.experience.id.

function onTemplateReady(event) {
  var player = brightcove.api.getExperience(event.target.experience.id);
  var videoPlayer = player.getModule(brightcove.api.modules.APIModules.VIDEO_PLAYER);
}

When using addEventHandler, you'll need to wrap functions in an anonymous function instead of using just the function name:

videoPlayer.addEventListener(brightcove.api.events.MediaEvent.PLAY, function(event) {onPlay(event)})
//instead of videoPlayer.addEventListener(brightcove.api.events.MediaEvent.PLAY, onPlay})

You could pass other modules etc to those functions if you need to, e.g. if this were done in the onTemplateReady above, the player can be available in the player handler:

videoPlayer.addEventListener(brightcove.api.events.MediaEvent.PLAY, function(event) {onPlay(event,player)})

See this example which uses some of the above techniques, which is an example of stopping other players when one plays.

于 2013-09-23T16:18:56.080 回答