开发者

HTML 5 audio tag: Can't get mp3 file to play on iPad Safari

开发者 https://www.devze.com 2023-01-23 00:02 出处:网络
I have an HTML5 app that\'s essentially a soundboard. You click an image and it plays an mp3 file. It works 开发者_JAVA百科fine on Chrome but not on my iPad Safari. The function looks like this:

I have an HTML5 app that's essentially a soundboard. You click an image and it plays an mp3 file. It works 开发者_JAVA百科fine on Chrome but not on my iPad Safari. The function looks like this:

<script type="text/javascript">

function playSound(theSound) {
    soundDir = "./sounds/";
    filename = soundDir + theSound;
    sound = new Audio(soundDir + theSound);
    sound.setAttribute("autoplay", "autoplay");
    document.getElementsByTagName("body")[0].appendChild(sound);
    return true;
}
</script>

And it's called like this:

onclick=playSound("knife.mp3")

What am I doing wrong?


More extensive research showed me that 1) Apple doesn't seem to like "autoplay" for bandwidth reasons, and 2) the jPlayer people are smarter than I am and have it working already.

0

精彩评论

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