SimonGoldstone
SimonGoldstone

Reputation: 5216

Windows Media Player JavaScript control - multiple players problems

hope you can help.

I have a screen in my ASP.net MVC3 application that displays several WindowsMediaPlayer objects. Excerpt from my view:

<object id="audio" width="100%" height="65" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" type="application/x-oleobject" name="mediaPlayer">
   <param name="URL" value="/QualityAssurance/PlayRecording/<%: Model.CustomerOrder.Id.ToString() %>/<%: System.IO.Path.GetFileName(Model.RecordingFilename) %>"/>
   <param name="SendPlayStateChangeEvents" value="true"/>
   <param name="AutoStart" value="false"/>
   <param name="PlayCount" value="1"/>
   <param name="stretchtofit" value="true"/>
   <param name="showstatusbar" value="true"/>
   <param name="enablepositioncontrols" value="true"/>
   <param name="showpositioncontrols" value="true"/>
   <param name="enabletracker" value="true"/>
   <param name="showcontrols" value="true"/>
   <param name="showaudiocontrols" value="true"/>
   <param name="enablecontextmenu" value="true"/>
</object>

There may be several of these players onscreen at any one time. I need to create a piece of JavaScript that stops playback of all of these media players. My code currently looks like this:

<script type="text/javascript" language="javascript">
    function stopAllMedia() {
        var elements = document.getElementsByTagName("object");
        var i = 0;
        for (i = 0; i < elements.length; i++) {
            stopMedia(document.getElementById(elements[i].id));
        }
    }

    function stopMedia(mediaPlayer) {
        var wmp = new Object();
        wmp.wmv = mediaPlayer.object;
        wmp.wmv.controls.stop();
    }
</script>

This code will successfully stop playback of the first WMP object, but not the others. However, if I put an alert('') inside stopMedia, it is getting called several times (i.e. once for each WMP on the page). But for some reason, it will just not control the other objects.

Can you help?

Thanks,

Simon.

Upvotes: 1

Views: 4386

Answers (1)

powerMicha
powerMicha

Reputation: 2773

Did you try to rewrite the {{{stopMedia}}} function?

function stopMedia(mediaPlayer) {
    mediaPlayer.controls.stop();
}

I am not sure if this is working, but have a try!

Upvotes: 1

Related Questions