firefox可以通過javascript控制Windows Media Player 11了

以前使用Windows Media Player 9時查看過sdk並沒有發現ff可以通過js可以控制Media Player,今天翻看微軟的msdn裏的Windows Media Player 11 SDK發現firefox居然也能使用js控制Media Player了。看

Using the Windows Media Player Control with Firefox

 

看錶格:

PARAM name

Internet
Explorer

Firefox with mime type
application/x-ms-wmp

Firefox with any
other mime type

autoStart

yes

yes

yes

balance

yes

yes

yes

baseURL

yes

yes

yes

captioningID

yes

yes

yes

currentMarker

yes

yes

yes

currentPosition

yes

yes

yes

defaultFrame

yes

no

no

enableContextMenu

yes

yes

yes

enabled

yes

yes

yes

enableErrorDialogs

yes

yes

no

fileName

no

yes

yes

fullScreen

yes

no

no

invokeURLs

yes

no

no

mute

yes

yes

yes

playCount

yes

yes

no

rate

yes

yes

yes

SAMIFileName

yes

yes

yes

SAMILang

yes

yes

yes

SAMIStyle

yes

yes

yes

SRC

no

yes

yes

stretchToFit

yes

yes

no

URL

yes

yes

yes

volume

yes

yes

yes

windowlessVideo

yes

yes

yes

出處http://msdn.microsoft.com/en-us/library/bb614511(VS.85).aspx

經過本人測試果然ff可以基本和ie一樣控制mp,效果也一樣。不過在ff下要安裝插件。

在sdk的Using the invokeURLs Property in a Web Page Displayed by Firefox 提供了一個簡單的例子

<HTML>
  <BODY OnLoad="Initialize()">

    <SCRIPT type="text/javascript">

      document.write('<OBJECT id="Player"');

      if(-1 != navigator.userAgent.indexOf("MSIE"))
      {              
        document.write(' classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6"');      
      }
      else if(-1 != navigator.userAgent.indexOf("Firefox"))
      {     
        document.write(' type="application/x-ms-wmp"');       
      } 

      document.write(' width=300 height=200>');
      document.write('<PARAM name="autoStart" value="false"/>');
      document.write('<PARAM name="url" value="c://MediaFiles//Glass.wmv"/>');
      document.write('</OBJECT>');
     
    </SCRIPT>

    <SCRIPT>
      function Initialize()
      {
        Player.settings.invokeURLs = false;
        Player.controls.play();
      }
    </SCRIPT>

  </BODY>
</HTML>

當用ff打開這網頁如果沒有插件ff就會提示安裝。

你有興趣的話也可以去測試一下,結合這個sdk完全可以製作一個自己的ff和ie兼容網頁播放器。

並且本人測試同樣在chrome上也可以兼容,但在控制音量上有些小問題。而Safari下可以運行但兼容不太好,有很大問題,Opera就根本不行了。

 

另外提示一下在ie下可以通過

<script language="jscript" for="mpObj" event=playStateChange(NewState)>myPlayer.playerStateChange(myPlayer, NewState);</script>
    <script language="jscript" for="mpObj" event=error()>myPlayer.error();</script>
    <script language="jscript" for="mpObj" event=Buffering(state)></script>
    <script language="jscript" for="mpObj" event=currentItemChange()></script>
    <script language="jscript" for="mpObj" event="currentPlaylistChange(change)"></script>

去檢測播放器的狀態改變而firefox不支持"jscript"因此這些代碼是不能使用的。但可以通過變通方法setInterval去輪詢播放器狀態解決。

下圖爲firefox下的情況

firefox下基於mediaplay11的web播放器

下圖爲chrome下的情況

chrome下的播放器

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章