Question

Here is my javascript code

$('.vdo_player1').html("<object id='myExperience185592012001' class='BrightcoveExperience'> <param name='bgcolor' value='#FFFFFF' /><param name='width' value='624' /> <param name='height' value='330' /><param name='playerID' value='1917830444001' /><param name='playerKey' value='AQ~~,AAABrLPpvnk~,7Q4Wbq_wEtPqLNVzhMk5nzVfbE6a6vSo' /> <param name='isVid' value='true' /><param name='isUI' value='true' /> <param name='dynamicStreaming' value='true' /> <param name='@videoPlayer' value='2045929343433301' /> </object> <script type='text/javascript'>brightcove.createExperiences();</script>");

The video is getting dispalyed properly.But I need to track when the video ends and call a struts 2 action class based on it.How can I do it?

Was it helpful?

Solution

Whilst user1190992's answer will work with a Flash player, it won't work with an HTML5 player as it uses the older Flash-only Player API. You should use Brightcove's Smart Player API which works with both Flash and HTML5 players.

First enable the API for the player you are using (in Video Cloud studio, player settings).

Add some additional parameters to your player code to enable the API.

<param name="includeAPI" value="true" /> 
<param name="templateLoadHandler" value="onTemplateLoaded" /> 
<param name="templateReadyHandler" value="onTemplateReady" /> 

Add javascript to set up the event listener

var player, modVP;

function onTemplateLoaded(experienceID) {
  player = brightcove.api.getExperience(experienceID);
  modVP = player.getModule(brightcove.api.modules.APIModules.VIDEO_PLAYER);
}

function onTemplateReady(evt) {
  modVP.addEventListener(brightcove.api.events.MediaEvent.COMPLETE, onComplete);
}

function onComplete(evt) {
  alert("Video ended");
}

See also Brightcove's doc: http://support.brightcove.com/en/video-cloud/docs/listening-events-using-smart-player-api

Note: This answer and question refers to Brightcove's legacy Smart Player, this doesn't apply to the current player version

OTHER TIPS

Using the API, you could write a function like

<script type="text/javascript">

   var bcExp;
   var modVP;

   function onTemplateLoaded(experienceID) {
       bcExp = brightcove.getExperience(experienceID);
       modVP = bcExp.getModule(APIModules.VIDEO_PLAYER);
       modVP.addEventListener(BCMediaEvent.COMPLETE, my_function);
   }

   function my_function(event) {
       /* DO YOUR STUFF IN HERE */
   }

</script> 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top