Search code examples
javascriptbrightcove

brightcove loadVideoById does nothing


I'm try to create a brightcove video player to play about 5 videos. I've created the player as such:

<script language="JavaScript" type="text/javascript"       src="http://admin.brightcove.com/js/BrightcoveExperiences.js"></script>
<object id="myExperience3775330164001" class="BrightcoveExperience">
    <param name="bgcolor" value="#FFFFFF" />
    <param name="playerID" value="2805093005001" />
    <param name="playerKey" value="AQ~~,AAABnWrZY8k~,bg2iiZ4K32IcUpn85Gn5TF9lWzVxKnlO" />
    <param name="isVid" value="true" />
    <param name="isUI" value="true" />
    <param name="dynamicStreaming" value="true" />
    <param name="@videoPlayer" value="3775330164001" />
    <param name="wmode" value="transparent" />
    <!-- smart player api params -->
    <param name="includeAPI" value="true" />
    <param name="templateLoadHandler" value="onTemplateLoad" />
    <param name="templateReadyHandler" value="onTemplateReady" />
    <param name="templateErrorHandler" value="onTemplateError" />
</object>

<script type="text/javascript">brightcove.createExperiences();</script>

Then I'm trying to swap out the video by calling loadVideoByID(12345)...this is a separate js file.

var player,
APIModules,
videoPlayer;

function onTemplateLoad(experienceID){
 player = brightcove.api.getExperience(experienceID);
 APIModules = brightcove.api.modules.APIModules;
 console.log("template loaded...");
}

function onTemplateReady(evt){
 videoPlayer = player.getModule(APIModules.VIDEO_PLAYER);
 console.log("template ready...");
}

$( document ).ready(function(){

// this script switches videos when 

    $( '.mlink').on("click", ".choose-video", function(event){

            event.preventDefault();
            $id = $(this).data("id");
            //console.log($id);
            switchvids($id, videoPlayer);

    });
});

var switchvids = function(id, vidplayer){
  console.log(id);
  console.log(vidplayer);
  try{
    vidplayer.loadVideoByID(id);
}
catch(error){
    console.log(error);
}

};

When my switchvids function is called nothing happens. No video is launched, no js errors. The console is showing the proper id and it is showing that vidplayer is a brightcove.api.modules.VideoPlayerModule. In the network panel I see a POST request go out to http://c.brightcove.com/services/messagebroker/amf?playerKey=AQ~~,AAABnWrZY8k~,bg2iiZ4K32IcUpn85Gn5TF9lWzVxKnlO and a response comes back but it is Content-Length: 26. Is this some sort of failed handshake? Has anyone seen anything like this before? The only thing I'm not sure about is the video ids. I pulled the ids off the brightcove documentation. I don't know if that is causing the problem. I would think the payload would contain an error message if I was trying to use videos that I was not authorized to use. My client has not yet provided me with ids to use.


Solution

  • loadVideoByID() returns false if an invalid ID is used. It doesn't throw an error.