- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我构建了一个 React 应用程序,可以在桌面网络浏览器上播放/暂停当前选定的音频:
playPreview() {
if (!this.state.isPlaying) {
this.setState({ isPlaying: true });
this.refs.audioRef.play();
} else {
this.setState({ isPlaying: false });
this.refs.audioRef.pause();
}
}
在 iOS 移动浏览器(safari 和 chrome mobile)上,我收到未处理的拒绝(NotSupprted 错误):不支持该操作。
我知道在 iOS 上音频必须通过用户手势播放的问题,但我用 onClick 触发了我的方法:
{!props.isPlaying
? (<MdPlayCircleOutline className="play-btn" onClick={() =>
props.playPreview()} />)
: (<MdPauseCircleOutline className="play-btn" onClick={() =>
props.playPreview()} />)
}
我在父应用程序组件中有一个隐藏元素:
<audio ref="audioRef" src={this.state.currentSongUrl} style={{ display: 'none' }} />
所以我假设它不起作用,因为 onClick 不是直接的音频元素?如果是这样的话,我知道如何结合这两个要求。
1 - 动态改变音频源2 - 交替播放和暂停
预先感谢任何见解和帮助!
-托德
最佳答案
发生这种情况可能是因为您使用了已弃用的 ref 语法。你应该尝试这样的事情:
<audio ref={(input) => {this.audioRef = input}} src={this.state.currentSongUrl} style={{ display: 'none' }} />
和
playPreview() {
if (!this.state.isPlaying) {
this.setState({ isPlaying: true });
this.audioRef.play();
} else {
this.setState({ isPlaying: false });
this.audioRef.pause();
}
}
如需引用,请访问:Refs and the DOM
关于reactjs - React - refs - 音频播放 - iOS 上未处理的拒绝(NotSupportedError),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48748063/
我无法使用我找到的任何教程使文件 API 系统正常工作。为了让代码正常工作,我已经尝试了所有这些。 window.storageInfo.requestQuota(PERSISTENT, size,
我使用以下代码行来连接到我的计算机的数据库实例。 cnx = mysql.connector.connect(host=Host, user=User, password=Password, data
我构建了一个 React 应用程序,可以在桌面网络浏览器上播放/暂停当前选定的音频: playPreview() { if (!this.state.isPlaying) { th
我正在创建一个自定义元素并将其 shadowRoot 设置为包含其他自定义元素,这会引发 NotSupportedError (DOM Exception 9): A newly constructe
我正在使用 JavaScript Web Audio API AudioContext 来播放音频。它可以与其他主要浏览器配合使用,但 MacOS 上的 Safari 在调用 webkitAudioC
我在 Linux 机器(在 AWS 中)的 Django 项目中使用: python 3.5.1 Django 1.11.7 我已经为我的项目创建了虚拟环境,并且所有的依赖项都完美地安装在那里。对于数
我正在运行一个 Electron (v2.0.3) 项目,它在 webview 中执行脚本。脚本之一是在条件下播放本地音频文件。 但是,如果在 webview 中调用音频播放将被拒绝,而如果在 ind
class M_Post(models.Model): '''' CODE '''' class M_File(models.Model): .... CODE .... class M_Post_F
这是我的第一个问题。 所以我有这个 github 页面,它可以与最新的 chromium 一起正常工作,但我无法让它在 safari 上工作。当我在 Safari 上单击播放按钮时,我得到了 Unha
当我在 CONFLICT 子句旁边创建更新规则时,就会抛出该错误。 这里是我的冲突代码 insert_query = "INSERT INTO my_company (id, name, login
当我尝试在本地运行 django 服务器时,出现此错误:“django.db.utils.NotSupportedError:需要 PostgreSQL 12 或更高版本(发现 11.19)。”。本地
我是一名优秀的程序员,十分优秀!