Open Windows Media Player via html

喜你入骨 提交于 2019-12-11 04:44:52

问题


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"> 

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!


回答1:


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 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>


来源:https://stackoverflow.com/questions/4849039/open-windows-media-player-via-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!