最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - audio not playing in iPad - Stack Overflow

programmeradmin4浏览0评论
<audio id="test" controls="controls">
    <source src="1.mp3" type="audio/mpeg" />
    <source src="1.ogg" type="audio/ogg" />
</audio>

js code to play video as dom loads

document.getElementById('test').load();
document.getElementById('test').play();

working in browsers but not in iPad, what I need to set?

<audio id="test" controls="controls">
    <source src="1.mp3" type="audio/mpeg" />
    <source src="1.ogg" type="audio/ogg" />
</audio>

js code to play video as dom loads

document.getElementById('test').load();
document.getElementById('test').play();

working in browsers but not in iPad, what I need to set?

Share Improve this question asked Nov 8, 2011 at 10:17 coure2011coure2011 42.6k87 gold badges225 silver badges361 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

According to apple's documentation, loading and playback of audio/video content has to be triggered from a user's action:

In Safari on iOS (for all devices, including iPad), where the user may be on a cellular network and be charged per data unit, preload and autoplay are disabled. No data is loaded until the user initiates it. This means the JavaScript play() and load() methods are also inactive until the user initiates playback, unless the play() or load() method is triggered by user action. In other words, a user-initiated Play button works, but an onLoad="play()" event does not.

This plays the movie: <input type="button" value="Play" onClick="document.myMovie.play()">

This does nothing on iOS: <body onLoad="document.myMovie.play()">

Taken from here: http://developer.apple./library/safari/#documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html

发布评论

评论列表(0)

  1. 暂无评论