Question

I need to catch an event using the Brightcove API. When the video finishes to play I execute a function. I followed the API guide on the website but it's the first time I'm using Brightcove so I'm bit confused. Here's my code:

    <script language="JavaScript" type="text/javascript" src="http://admin.brightcove.com/js/BrightcoveExperiences.js"></script>

         <object id="myExperience1537710931001" class="BrightcoveExperience">
            <param name="bgcolor" value="#FFFFFF" />
            <param name="width" value="764" />
            <param name="height" value="455" />
            <param name="playerID" value="1537479248001" />
            <param name="playerKey" value="AQ~~,AAABZfMS9tk~,qKtLVPwo3pzgDkN5hMeILjqzKpujZdaw" />
            <param name="isVid" value="true" />
            <param name="isUI" value="true" />
            <param name="dynamicStreaming" value="true" />
            <param name="includeAPI" value="true" />
            <param name="templateLoadHandler" value="myTemplateLoaded" />
            <param name="templateReadyHandler" value="onTemplateReady" />
            <param name="@videoPlayer" value="1537710931001" />
        </object>


                <script type="text/javascript">

                    var player;
                    var modVP;
                    var modExp;
                    var modCon;

            function myTemplateLoaded(experienceID) {
                player = brightcove.api.getExperience(experienceID);
                modVP = player.getModule(brightcove.api.modules.APIModules.VIDEO_PLAYER);
                modExp = player.getModule(brightcove.api.modules.APIModules.EXPERIENCE);
                modCon = player.getModule(brightcove.api.modules.APIModules.CONTENT);
                modExp.addEventListener(brightcove.api.events.ExperienceEvent.TEMPLATE_READY, onTemplateReady);
            }

            function onTemplateReady(evt) {
                modVP.addEventListener(brightcove.api.events.MediaEvent.BEGIN, onMediaEventFired);
                modVP.addEventListener(brightcove.api.events.MediaEvent.CHANGE, onMediaEventFired);
                modVP.addEventListener(brightcove.api.events.MediaEvent.COMPLETE, onMediaEventFired);
                modVP.addEventListener(brightcove.api.events.MediaEvent.ERROR, onMediaEventFired);
                modVP.addEventListener(brightcove.api.events.MediaEvent.PLAY, onMediaEventFired);
                modVP.addEventListener(brightcove.api.events.MediaEvent.PROGRESS, onMediaProgressFired);
                modVP.addEventListener(brightcove.api.events.MediaEvent.STOP, onMediaEventFired);
            }


            function onMediaEventFired(evt) {
                if (evt.type === brightcove.api.events.MediaEvent.STOP) {
                    alert('Hello!!!!');
                }
            }
</script>

Not sure what I'm doing wrong but the alert doesn't show when the video has finished to play. Any idea?

Thanks
Mauro

Was it helpful?

Solution

The callbacks work if you swap the player out. This would indicate you need to enable the API for your specified player. This can be done by editing the player settings within Brightcove admin (http://support.brightcove.com/en/docs/editing-settings-players).

You may also need to specify your handlers by adding params to the flash object, E.G.

<param name="templateLoadHandler" value="myTemplateLoaded" />

You will also need to change your event handler to test the event object type not data like so:

    function onMediaEventFired(evt) {

        if (evt.type === brightcove.api.events.MediaEvent.COMPLETE) {
            alert('Hello!!!!');
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top