<audio id="test" controls="controls"> <source src="1.mp3" type="audio/mpeg" /> <source src="1.ogg" type="audio/ogg" /> </audio>
js代码以dom加载播放视频
document.getElementById('test').load(); document.getElementById('test').play();
在浏览器中工作但在iPad中工作,我需要设置什么?
解决方法
根据apple的文档,音频/视频内容的加载和回放必须通过用户的操作触发:
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()">