gpt4 book ai didi

android - 在 android 的 google chrome 上顺序播放声音(考虑到播放声音的新限制)

转载 作者:太空狗 更新时间:2023-10-29 16:34:25 24 4
gpt4 key购买 nike

我有一个播放连续声音的小应用程序(一个播放单词音节的教学应用程序)

这可以通过在每个声音停止播放后立即触发一个事件来实现。像这样的东西:

var sounds = new Array(new Audio("1.mp3"), new Audio("2.mp3"));
var i = -1;
playSnd();

function playSnd() {
i++;
if (i == sounds.length) return;
sounds[i].addEventListener('ended', playSnd);
sounds[i].play();
}

(source)

但是,现在 android chrome 对如何播放声音实现了一些新限制:声音事件必须全部由用户操作触发。

所以,当我运行与上面非常相似的代码时,第一个声音播放,然后我得到

Uncaught (in promise) DOMException: play() can only be initiated by a user gesture.

如何在 Android 的 Chrome 上播放在运行时确定的一系列声音?

最佳答案

首先,Android 版 Google Chrome 一直存在限制,即不允许应用程序在没有明确操作 HTML 音频 em> 由用户。但是,在大多数情况下,它与普通浏览器处理它的方式不同。

The reason, as Chromium Org puts it, is that, Autoplay is not honored on android as it will cost data usage.

You may find more details on the same here.

Apart from the fact that this results in wastage of bandwidth, this also makes some sense, since mobile devices are used in public and in houses, where unsolicited sound from random Web sites could be a nuisance.

但是,在后来的版本中,这个想法被否决了,Android 上的 Chrome 开始允许在其上自动播放 HTML 音频视频 .经过一系列审查和讨论后,此功能再次恢复到原来的状态,用户必须执行此操作才能在 Android 版 Chrome 上调用 HTML 音频和视频 .

Here is something that I found more on the same. As it says, the reason stated was that "We're going to gather some data about how users react to autoplaying videos in order to decide whether to keep this restriction". And hence the playing option without a user action was reverted back.

You can also find more about the blocking of _autoplay of audio(s) and video(s) here on Forbes and The Verge.

不过,我建议您尝试一下,这将帮助您实现您的目标。您所要做的就是复制此代码并粘贴到您的 Android 版 Chrome 中。这可以帮助您重置默认设置为不允许在没有用户交互的情况下播放 HTML 音频和视频的标志:

chrome://flags/#disable-gesture-requirement-for-media-playback

OR

about:flags/#disable-gesture-requirement-for-media-playback

如果上述过程对您没有帮助/不起作用,您可以这样做:

Go into chrome://flags OR about:flags (this will direct you to chrome://flags) and Enable the "Disable gesture requirement for media playback" option (which is actually the same as the above URL specified).

关于android - 在 android 的 google chrome 上顺序播放声音(考虑到播放声音的新限制),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47143562/

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