本文介绍了通过html打开Windows Media Player的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何打开Windows媒体播放器并通过html文件播放mp3文件?我不希望嵌入mp3

How can I open windows media player and play a mp3 file via a html file? I don't want to embed the mp3 with

<embed src="mp3.mp3" autostart="true" loop="true" hidden="true"> 

我希望程序的Windows媒体播放器弹出并播放mp3。我怎样才能做到这一点?也许用Java脚本?如果是这样如何?谢谢!

I want the program windows media player to pop up and play the mp3. How can I do that? Maybe with Java script? If so how? Thanks!

推荐答案

您可以为此创建隐藏框架,请注意,只有在IE浏览器中才会导致WMP弹出播放它,其他浏览器将播放内部。

You can create hidden frame for this, note that only in IE browser it will actually cause WMP to pop up and play it, other browsers will play it "internally".

在示例中,代码将播放文本框中给出的文件:

In the example the code will play file given inside textbox:

File: <input type="text" id="txtMusicFileName" /><br />
<button type="button" onclick="PlayMusicClicked();">Play</button>

所需的JavaScript代码:

JavaScript code required:

<script type="text/javascript">
function PlayMusicClicked() {
    var sFileName = document.getElementById("txtMusicFileName").value;
    if (sFileName.length > 3) {
        var oFrame = document.getElementById("MusicFrame");
        if (!oFrame) {
            oFrame = document.createElement("iframe");
            oFrame.id = "MusicFrame";
            oFrame.style.display = "none";
            document.body.appendChild(oFrame);
        }
        oFrame.src = sFileName;
    }
}
</script>

这篇关于通过html打开Windows Media Player的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 13:39