javascript – 音频无法在iPad上播放

前端之家收集整理的这篇文章主要介绍了javascript – 音频无法在iPad上播放前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<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()">

取自这里:http://developer.apple.com/library/safari/#documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html

原文链接:https://www.f2er.com/js/240929.html

猜你在找的JavaScript相关文章