<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?
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.com/library/safari/#documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With