1
votes

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.

1
@MilkyWayJoe, sorry for the delay - missed your message. In the end, I decided to put a single Media Player on the page and just have "play" and "stop" buttons for each piece of media instead. This worked much better and is probably much more efficient resources-wise too.SimonGoldstone
I don't know if it still helps or even if it's relevant for you now, but take a look at this question. It can be adapted to multiple playersMilkyWayJoe

1 Answers

1
votes

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!