javascript - 播放/暂停 HTML 音频在 iOS 上不起作用
问题描述
我已经通过 JS 在我的网站中实现了一个带有播放/暂停按钮的 html 音频。适用于除 iOS 之外的所有桌面和移动设备。
这不是自动播放,所以我认为它不会破坏任何 iOS 政策?
这是我正在使用的代码。
PS:尝试在stackoverflow上搜索,但没有发现任何有用的东西。
<style>
#demo {
width: 60px;
height: 60px;
outline: none;
}
</style>
<button onclick="Play()" id="demo"></button>
<audio id="player" preload="auto">
<source src="https://s3.eu-central-1.amazonaws.com/radmitry/Yoshio_Chino-We_Pray_For_Japan.mp3">
</audio>
<script>
var audio = document.getElementById("player");
audio.volume = 0.5;
var butn = document.getElementById("demo");
butn.style.background = "url(https://uploads-ssl.webflow.com/5acdf398c6f3e7252e9a31b9/5ad9f901d9a651ff58dad03b_play.svg) no-repeat";
function Play() {
if(audio.paused) {
audio.play();
butn.style.background = "url(https://uploads-ssl.webflow.com/5acdf398c6f3e7252e9a31b9/5ad9f8b88fb8e56097aa04ca_pause.svg) no-repeat";
}
else {
audio.pause();
butn.style.background = "url(https://uploads-ssl.webflow.com/5acdf398c6f3e7252e9a31b9/5ad9f901d9a651ff58dad03b_play.svg) no-repeat";
}
}
</script>
解决方案
推荐阅读
- java - 在 Spring JPA 中调用 saveAll 后相关实体为空
- r - 带有 Rmarkdown 的 Tufte 文件中的全宽图像
- django - Django 千位和小数分隔
- java - 大于 N(重访)
- linq - 在 LINQPad 5 中找不到 System.Data.Entity.DbFunctions.TruncateTime
- ios - 如何快速从 Firebase Firestore 中删除当前用户的特定文档?
- html - 相同的引导列代码功能不同
- python - 获取查找:路径必须在 subprocess.check_output 表达式错误之前
- doxygen - 我可以使用 Doxygen 链接到另一个源文件吗
- php - 如何做一个接受两个输入或一个输入的 laravel 过滤器