Is there a documented JavaScript API for Windows Media Player?
Asked Answered
C

5

7

I want to use JavaScript to control an embedded Windows Media Player, as well as access any properties that the player exposes. I've found a few hacky examples online, but nothing concrete.

I really need access to play, pause, stop, seek, fullscreen, etc. I'd also like to have access to any events the player happens to broadcast.

Help would be wonderful (I already have a Flash equiv, just so you know), thanks!

Coranto answered 18/11, 2008 at 17:57 Comment(0)
C
6

There is an API in Microsoft's developer center, but it will only work if you embed windows media player using active-x.

To "learn" more about the API, check out MSDN: http://msdn.microsoft.com/en-us/library/dd564034(VS.85).aspx

Coranto answered 7/4, 2009 at 23:30 Comment(1)
The link is for Media Player in Microsoft Windows CE .NET 4.2 I don't think that is the operating system you really care aboutThermophone
A
11

The API requires ActiveX connectivity native to Internet Explorer, or can use a plugin for Firefox.

Here's a sample page that might get you started.

<html>
<head>
  <title>so-wmp</title>
  <script>

    onload=function() {
      player = document.getElementById("wmp");
      player.URL = "test.mp3";
    };

    function add(text) {
      document.body
        .appendChild(document.createElement("div"))
        .appendChild(document.createTextNode(text));
    };

    function handler(type) {
      var a = arguments;
      add(type +" = "+ PlayStates[a[1]]);
    };

    // http://msdn.microsoft.com/en-us/library/bb249361(VS.85).aspx
    var PlayStates = {
       0: "Undefined", // Windows Media Player is in an undefined state.
       1: "Stopped", // Playback of the current media item is stopped.
       2: "Paused", // Playback of the current media item is paused. When a media item is paused, resuming playback begins from the same location.
       3: "Playing", // The current media item is playing.
       4: "ScanForward", // The current media item is fast forwarding.
       5: "ScanReverse", // The current media item is fast rewinding.
       6: "Buffering", // The current media item is getting additional data from the server.
       7: "Waiting", // Connection is established, but the server is not sending data. Waiting for session to begin.
       8: "MediaEnded", // Media item has completed playback.
       9: "Transitioning", // Preparing new media item.
      10: "Ready", // Ready to begin playing.
      11: "Reconnecting" // Reconnecting to stream.
    };

  </script>
  <script for="wmp" event="PlayStateChange(newState)">
    // http://msdn.microsoft.com/en-us/library/bb249362(VS.85).aspx
    handler.call(this, "playstatechange", newState);
  </script>
</head>
<body>
  <div id="page">
    <object id="wmp"
       classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6"
          type="application/x-oleobject">
    </object>
  </div>
</body>
</html>
Adonic answered 8/4, 2009 at 0:30 Comment(0)
C
6

There is an API in Microsoft's developer center, but it will only work if you embed windows media player using active-x.

To "learn" more about the API, check out MSDN: http://msdn.microsoft.com/en-us/library/dd564034(VS.85).aspx

Coranto answered 7/4, 2009 at 23:30 Comment(1)
The link is for Media Player in Microsoft Windows CE .NET 4.2 I don't think that is the operating system you really care aboutThermophone
U
4

Windows media player is exposed as an activex control that any scripting language running in the windows script host should be able to access. You should be able to use jscript to control it. Jscript is microsofts implimentation of java script. For information on what objects and methods are availble using jscript for windows media player se this link.

Unwholesome answered 18/11, 2008 at 19:56 Comment(0)
M
0

There is no open JavaScript library as far as I know for crossbrowser clientside handling of a WMP player. However, this link should make it quite easy for you to start your own little library. The code might need some updating and testing in modern browser versions but you have the basics there.

The library your searching for would be a great idea for a Google Code project, I guess that while everyone today is using Adobe Flash with sIFR / swfobject or Microsoft Silverligt with sistr etc, there are not much interest to write clientside script controlling for WMP.

Metastasis answered 18/11, 2008 at 20:18 Comment(1)
Sadly I have to deal with a big old corporate client whose IT dept thinks that adding Flash or Silverlight to the OS image might cause conflicts. Hooray for client work... thanks for the link though, it looks helpful.Coranto
T
0

Should use next WMP object (works in Chrome, FF, Safari)

    objPlayer = document.getElementById("wmp");           
    objPlayer.controls.stop();
    objPlayer.URL = this.url;
    objPlayer.controls.play();

<EMBED id="wmp" TYPE="application/x-mplayer2" name="MediaPlayer" width="0" height="0" ShowControls="0" ShowStatusBar="0" ShowDisplay="0" autostart="0"></EMBED>
Thoroughwort answered 17/1, 2013 at 5:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.