微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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.jb51.cc/js/240929.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐