7

JavaScript を使用して、組み込みの Windows Media Player を制御し、プレーヤーが公開するプロパティにアクセスしたいと考えています。オンラインでいくつかのハッキーな例を見つけましたが、具体的なものは何もありません。

再生、一時停止、停止、シーク、フルスクリーンなどへのアクセスが本当に必要です。また、プレイヤーがたまたまブロードキャストするイベントへのアクセスも必要です。

助けていただければ幸いです (私はすでに Flash の同等品を持っています)、ありがとう!

4

5 に答える 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>
于 2009-04-08T00:30:28.900 に答える
6

Microsoft のデベロッパー センターに API がありますが、active-x を使用して Windows Media Player を埋め込んだ場合にのみ機能します。

API の詳細については、MSDN を参照してください: http://msdn.microsoft.com/en-us/library/dd564034(VS.85).aspx

于 2009-04-07T23:30:58.683 に答える
4

Windows Media Player は、Windows スクリプト ホストで実行されている任意のスクリプト言語がアクセスできる ActiveX コントロールとして公開されます。jscriptを使用して制御できるはずです。Jscript は、java スクリプトの Microsoft 実装です。Windows Media Player の jscript を使用して利用できるオブジェクトとメソッドについては、このリンクを参照してください。

于 2008-11-18T19:56:13.683 に答える
0

私が知る限り、WMP プレーヤーのクロスブラウザー クライアント側処理についてオープンな JavaScript ライブラリはありません。ただし、このリンクにより、独自の小さなライブラリを簡単に開始できるはずです。最新のブラウザー バージョンでは、コードの更新とテストが必要になる場合がありますが、基本的な操作は完了しています。

あなたが探しているライブラリは、Google Code プロジェクトの素晴らしいアイデアです。今日、誰もが Adob​​e Flash をsIFR / swfobjectで使用したり、Microsoft Silverligt をsistrで使用したりしていますが、WMP を制御するクライアント側のスクリプトを作成することにはあまり関心がないと思います。

于 2008-11-18T20:18:41.063 に答える
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>
于 2013-01-17T05:26:38.143 に答える