有没有针对Windows Media Player的JavaScript API文档记录?

7
我希望使用JavaScript来控制嵌入的Windows Media Player,并访问播放器公开的任何属性。我在网上找到了一些hacky示例,但没有实质性的内容。
我真的需要访问播放、暂停、停止、快进、全屏等功能。我还希望访问播放器可能广播的任何事件。
如果可以帮忙就非常感谢了(我已经有一个Flash替代品,只是让您知道一下),谢谢!
5个回答

11

该API需要Internet Explorer原生支持的ActiveX连接,或者可以使用Firefox插件

这里是一个可能会帮助您入门的示例页面。

<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>

6

1
链接是用于 Microsoft Windows CE .NET 4.2 中的媒体播放器。我认为那不是你真正关心的操作系统。 - Ron Harlev

4

Windows媒体播放器以ActiveX控件形式公开,任何在Windows脚本主机中运行的脚本语言都应该能够访问它。您应该能够使用JScript来控制它。JScript是微软对JavaScript的实现。要了解可使用JScript控制Windows Media Player的对象和方法,请参阅此链接。


0

据我所知,目前没有开放的JavaScript库可用于跨浏览器客户端处理WMP播放器。然而,这个链接应该可以让你很容易地开始自己的小型库。代码可能需要在现代浏览器版本中进行更新和测试,但基础知识已经在那里了。

你正在寻找的库对于Google Code项目来说是一个好主意,我猜想,当今每个人都在使用sIFR/swfobject与Adobe Flash或sistr等Microsoft Silverligt,因此没有太多兴趣编写控制WMP的客户端脚本。


很遗憾,我必须处理一个老大的企业客户,他们的IT部门认为将Flash或Silverlight添加到操作系统映像中可能会导致冲突。客户工作万岁...不过还是谢谢你提供的链接,看起来很有帮助。 - ironkeith

0

应该使用下一个 WMP 对象(适用于 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>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接