开发者

Open Windows Media Player via html

开发者 https://www.devze.com 2023-02-07 10:10 出处:网络
How can I open windows media player and play a mp3 file via a html file? I don\'t want to embed the开发者_JAVA技巧 mp3 with

How can I open windows media player and play a mp3 file via a html file? I don't want to embed the开发者_JAVA技巧 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!


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

精彩评论

暂无评论...
验证码 换一张
取 消