title: Windows Media Player JavaScript control - multiple players problems
body: <p>hope you can help.</p>
  
  <p>I have a screen in my ASP.net MVC3 application that displays several WindowsMediaPlayer objects. Excerpt from my view:</p>
  
  <pre><code>&lt;object id="audio" width="100%" height="65" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" type="application/x-oleobject" name="mediaPlayer"&gt;
     &lt;param name="URL" value="/QualityAssurance/PlayRecording/&lt;%: Model.CustomerOrder.Id.ToString() %&gt;/&lt;%: System.IO.Path.GetFileName(Model.RecordingFilename) %&gt;"/&gt;
     &lt;param name="SendPlayStateChangeEvents" value="true"/&gt;
     &lt;param name="AutoStart" value="false"/&gt;
     &lt;param name="PlayCount" value="1"/&gt;
     &lt;param name="stretchtofit" value="true"/&gt;
     &lt;param name="showstatusbar" value="true"/&gt;
     &lt;param name="enablepositioncontrols" value="true"/&gt;
     &lt;param name="showpositioncontrols" value="true"/&gt;
     &lt;param name="enabletracker" value="true"/&gt;
     &lt;param name="showcontrols" value="true"/&gt;
     &lt;param name="showaudiocontrols" value="true"/&gt;
     &lt;param name="enablecontextmenu" value="true"/&gt;
  &lt;/object&gt;
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>&lt;script type="text/javascript" language="javascript"&gt;
      function stopAllMedia() {
          var elements = document.getElementsByTagName("object");
          var i = 0;
          for (i = 0; i &lt; elements.length; i++) {
              stopMedia(document.getElementById(elements[i].id));
          }
      }
  
      function stopMedia(mediaPlayer) {
          var wmp = new Object();
          wmp.wmv = mediaPlayer.object;
          wmp.wmv.controls.stop();
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>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.</p>
  
  <p>Can you help?</p>
  
  <p>Thanks,</p>
  
  <p>Simon.</p>