DivX Web Player Plug-In Samples: JavaScript Callbacks



JavaScript Callbacks

This sample shows how to pass JavaScript callbacks to the plug-in to receive information during download and playback.

It uses both a global space callback and an object function callback to demonstrate that both are possible. The results are displayed below:


Current Time: second(s).
Current Status: .

The JavaScript code used in this sample is the following:


    <script type="text/javascript">

    //
    // This is a global space JS function used by
    // the plug-in as a callback when data is downloaded
    //

    function myTimeCallback(current)
    {
         document.getElementById('currentTime').innerHTML = current;
    }

    //
    // This is an object defined to have a
    // local callback function, that we will
    // pass to the plugin as statusParameter
    //

    function DivXPluginSinks()
    {

        this.statusCallbackSink = function(status)
        {
            var s = parseInt(status);

            switch(s)
            {
                 case 10: // STATUS_PLAYING
                 document.getElementById('currentStatus').innerHTML = 'Playing';
                 break;

                 case 11: // STATUS_PAUSED
                 document.getElementById('currentStatus').innerHTML = 'Paused';
                 break;

                 case 12: // STATUS_FF
                 document.getElementById('currentStatus').innerHTML = 'Fast Forwarding';
                 break;

                 case 13: // STATUS_RW
                 document.getElementById('currentStatus').innerHTML = 'Rewinding';
                 break;

                 case 2:  // VIDEO_END
                 case 14: // STATUS_STOPPED
                 document.getElementById('currentStatus').innerHTML = 'Stopped';
                 break;
            }
        }
    }

    // Create an instance of the object

    myDivXPlugin = new DivXPluginSinks()

    </script>
    

It defines the global function myTimeCallback() and the object DivXPluginSinks which has a function statusCallbackSink. We also create one instance of the DivXPluginSinks object called myDivXPlugin.

Both the global function and the object function are passed as timeCallback and statusCallback callback parameters in the object and embed tags as follows:


    <object classid="clsid:67DABFBF-D0AB-41fa-9C46-CC0F21721616"
            width="320" height="212"
            codebase="http://go.divx.com/plugin/DivXBrowserPlugin.cab">

            <param name="src" value="../../videos/video3.divx" />
            <param name="timeCallback" value="myTimeCallback" />
            <param name="statusCallback" value="myDivXPlugin.statusCallbackSink" />

            <embed type="video/divx" src="../../videos/video3.divx"
                   width="320" height="212" timeCallback="myTimeCallback"
                   statusCallback="myDivXPlugin.statusCallbackSink"
                   pluginspage="http://go.divx.com/plugin/download/">
            </embed>
    </object>
    


Back to samples index