简体   繁体   中英

test for browser's ability to play a wav file in javascript

Is there a way to test for browser's ability to play a wav file in javascript

function playSound(myWAVfile)
    {   
        if (soundEmbed)
        {
           document.body.removeChild(soundEmbed);
        }
        soundEmbed = document.createElement("embed");
        soundEmbed.setAttribute("src", myWAVfile);
        soundEmbed.setAttribute("hidden", true);
        soundEmbed.setAttribute("autostart", true);
        document.body.appendChild(soundEmbed);
    }

这应该对你有很大的帮助: http//www.schillmania.com/projects/soundmanager2/

you can use html5

<audio id="audio-tag-element" controls="" src=myWAVfile tabindex="0"></audio>

Ie8 and less will not work

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