是否有针对 Windows Media Player 的记录的 JavaScript API?

发布于 2024-07-09 05:57:10 字数 189 浏览 10 评论 0原文

我想使用 JavaScript 来控制嵌入式 Windows Media Player,以及访问播放器公开的任何属性。 我在网上找到了一些黑客示例,但没有具体的。

我确实需要访问播放、暂停、停止、搜索、全屏等。我还想访问播放器播放的任何事件。

如果有帮助那就太好了(我已经有一个 Flash 设备,只是让你知道),谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

不打扰别人 2024-07-16 05:57:10

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>

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>
烟织青萝梦 2024-07-16 05:57:10

微软的开发者中心有一个API,但是只有当您使用active-x嵌入Windows Media Player时它才起作用。

要“了解”有关 API 的更多信息,请查看 MSDN: http://msdn.microsoft.com/en-us/library/dd564034(VS.85).aspx

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

颜漓半夏 2024-07-16 05:57:10

Windows 媒体播放器作为 ActiveX 控件公开,在 Windows 脚本宿主中运行的任何脚本语言都应该能够访问。 您应该能够使用 jscript 来控制它。 Jscript 是微软对java 脚本的实现。 有关使用适用于 Windows Media Player 的 jscript 可以使用哪些对象和方法的信息,请参阅 此链接。

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.

披肩女神 2024-07-16 05:57:10

据我所知,还没有开放的 JavaScript 库可用于 WMP 播放器的跨浏览器客户端处理。
但是,此链接应该让您轻松创建自己的小图书馆。 该代码可能需要在现代浏览器版本中进行一些更新和测试,但您已经具备了基础知识。

您搜索的库对于 Google Code 项目来说是一个好主意,我想虽然今天每个人都在使用 Adob​​e Flash 和 sIFR / swfobject 或 Microsoft Silverligt 以及 sistr 等,没有太多兴趣编写控制 WMP 的客户端脚本。

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.

寄居人 2024-07-16 05:57:10

应该使用下一个 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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文