1

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.

SimonGoldstone
  • 5,096
  • 3
  • 27
  • 38
  • @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 Sep 06 '12 at 16:37
  • I don't know if it still helps or even if it's relevant for you now, but take a look at [this question](http://stackoverflow.com/questions/10436396/embedded-player-does-not-work-in-remote-browser/10437201#10437201). It can be adapted to multiple players – MilkyWayJoe Sep 06 '12 at 17:07

1 Answers1

1

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!

powerMicha
  • 2,753
  • 1
  • 24
  • 31
  • Hi @poweMicha, sorry it took so long to respond - I missed your answer. In the end, I decided to stop using several Media Player objects and instead just use one and have several play and stop buttons instead, each button sending a command to my single player. This was a much better implementation. But thanks for your suggestion. – SimonGoldstone Sep 06 '12 at 16:35