Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

audio not playing in iPad

<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?

like image 277
coure2011 Avatar asked Nov 08 '11 10:11

coure2011


1 Answers

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

like image 134
Variant Avatar answered Sep 28 '22 06:09

Variant