gpt4 book ai didi

javascript - iPad 不播放音频

转载 作者:太空狗 更新时间:2023-10-29 14:56:28 24 4
gpt4 key购买 nike

<audio id="test" controls="controls">
<source src="1.mp3" type="audio/mpeg" />
<source src="1.ogg" type="audio/ogg" />
</audio>

在 dom 加载时播放视频的 js 代码

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

关于javascript - iPad 不播放音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8048873/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com