【发布时间】:2020-12-03 14:20:21
【问题描述】:
在我的 React 应用程序中,我在 Safari 中遇到了一个问题(这在 Chrome 和 Firefox 中运行良好),当我将鼠标悬停在视频上播放它时,我收到以下错误:
NotAllowedError: 请求不被用户代理或 当前上下文中的平台,可能是因为用户拒绝 权限。
相关代码块是这样的:
{ this.state.url ?
<video className="video"
onMouseOver={event => {
this.onVideoPlay(this.state.url, event);
}}
onMouseOut={event => {
this.onVideoPause(this.state.url, event);
}}
src={`${this.state.url}`} >
</video>
: null
}
而我的两个函数是这样的:
onVideoPlay = async (videoUrl, event) => {
if (!videoUrl || !event || videoUrl === 'url(${videoBg})') return;
if (!this.state.isPlaying) {
await event.target.play();
this.setState({ isPlaying: true });
}
};
onVideoPause = async (videoUrl, event) => {
if (!videoUrl || !event) return;
if (this.state.isPlaying) {
await event.target.pause();
this.setState({ isPlaying: false });
}
}
这里有什么问题,我该如何解决?
【问题讨论】:
标签: reactjs safari html5-video