我想使用JavaScript来控制嵌入式Windows Media Player,以及访问播放器公开的任何属性。我在网上发现了一些黑客的例子,但没有具体的。是否有适用于Windows Media Player的JavaScript文档?
我真的需要进入播放,暂停,停止,寻找,全屏等。我还想访问玩家恰好播放的任何事件。
帮助将是美好的(我已经有一个Flash equiv,只是你知道),谢谢!
我想使用JavaScript来控制嵌入式Windows Media Player,以及访问播放器公开的任何属性。我在网上发现了一些黑客的例子,但没有具体的。是否有适用于Windows Media Player的JavaScript文档?
我真的需要进入播放,暂停,停止,寻找,全屏等。我还想访问玩家恰好播放的任何事件。
帮助将是美好的(我已经有一个Flash equiv,只是你知道),谢谢!
微软开发人员中心有一个API,但只有在使用active-x嵌入Windows媒体播放器时才能使用。
“学习” 更多关于API,看看MSDN:http://msdn.microsoft.com/en-us/library/dd564034(VS.85).aspx
Windows媒体播放器作为activex控件公开,在Windows脚本宿主中运行的任何脚本语言都应该能够访问它。你应该可以使用jscript来控制它。 J脚本是微软java脚本的实现。有关使用jscript为Windows媒体播放器提供哪些对象和方法的信息,请参阅使用jscript for windows媒体播放器se this link.
据我所知,对于交叉浏览器客户端处理WMP播放器,没有开放的JavaScript库。 但是,this link应该让你很容易开始自己的小型图书馆。代码可能需要在现代浏览器版本中进行一些更新和测试,但您有基本知识。
库您搜索的将是一个谷歌代码项目一个伟大的想法,我想,虽然现在大家都在使用Adobe Flash与sIFR/swfobject或Microsoft Silverligt与sistr等,没有太大的兴趣编写客户端脚本控制WMP。
可悲的是我不得不面对一个大的老企业客户,其IT部门认为,加入Flash或Silverlight的OS图像可能会导致冲突。万岁客户工作...感谢您的链接,但看起来很有帮助。 – ironkeith 2008-11-18 20:46:09
的API需要的ActiveX连接原产于Internet Explorer或可以使用plugin for 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>
应该使用下一个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>
该链接适用于Microsoft Windows CE .NET 4.2中的媒体播放器 我不认为这是您真正关心的操作系统 – 2009-07-31 20:56:33