简体   繁体   中英

Can't play wav file from Javascript in Firefox for Mac

I have the following html file that plays a wav file when the user hovers over the 'Play' anchor tag. It works perfectly on IE, Chrome, Firefox, Opera, Safari on both Windows and Mac - except for Firefox on the Mac which does not play the file.

We know the file type is supported because if the autostart attribute of the embed tag is set to true then the wav file plays as expected in Firefox for Mac, but the mouseover of the anchor tag fails to play the file.

Any ideas?

<html>
<head>
<title></title>
<script>
function PlayAudio() {
    var s = document.getElementById("soundFile");
    s.Play();
}
</script>
</head>
<body>
    <embed src="MySound.wav" enablejavascript="true" type="audio/wav" autostart="false" width="0" height="0" id="soundFile" />
    <a href="#" onmouseover="PlayAudio()">Play</a>     
</body>
</html>

UPDATE

Still no success after 3 weeks. Can anyone help with this?

I fixed this problem by using javascript to create embed when want to play and remove it to stop. And the embed has autostart="true".

function Play() {
    // Create and append <embed> element.
}

function Stop() {
    // Remove <embed> element.
}

It may be because the file type is not supported. Try using an MP3 format, which will also be smaller, which is a bonus (typically about one tenth of the size of a WAV file).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM