<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 badges1 Answer
Reset to default 8According 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