javascript - Javascript - 音频元素不在 iOS 上播放
问题描述
每当我翻书时,我都会尝试播放音频元素。音频元素仅在书的第一页播放,但是当我翻页并触发功能bookTurned()
时,音频不会在其他翻页上播放。此问题仅在 iOS 上发生,因为在每个其他 Web 浏览器上都会相应地播放音频。我已经看到这在 iOS 上是一个很常见的问题,但我无法弄清楚我需要做什么才能绕过这个问题并使其正常工作。有人可以解释一下为了在 iOS 上进行这项工作需要做什么吗?
编辑:在 iOS 上,我收到以下错误:
NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.
async bookTurned(event, page, pageObject) {
// Set first page turn
if (!bookTimer) {
bookTimer = new Timer();
}
// Determine direction
const direction = page > prevPage ? DIRECTION.RIGHT : DIRECTION.LEFT;
// Update turn index
currTurnIndex = convertPageNumberToTurnIdx(page);
// Play audio corresponding to the two pages we just turned to.
await BOOK_AUDIO_PLAYER.play(currTurnIndex + 1);
// Recalc max pages since turn js dynamically renders pages
const currMaxPages = calcMaxPages();
if (currMaxPages > maxPages) {
maxPages = currMaxPages;
}
}
BOOK_AUDIO_PLAYER
处理音频
解决方案
推荐阅读
- google-apps-marketplace - G Suite Marketplace 上的屏幕截图未更新
- mysql - 在 Dockerfile 中创建动态用户 - MySQL
- c++ - Docker 容器中的 MXE Qt5 应用程序构建失败
- html - 将英雄图像插入一个部分
- cuda - 如何使用可视化分析器识别 CUDA 代码的带宽和失败率?
- angular - Angular - @Input 和 @Output 与可注入服务
- python-3.x - python中的AttributeError:对象没有属性
- sql - 如何通过postgresql中的公共列查找两个表之间的特定行?
- permissions - Azure AD 应用程序所需权限列表不包括所有 API
- python - 带有单个数据点的 pyplot 条形图