视频自动播放功能无法在Chrome和Safari浏览器中正常运行吗?

编程入门 行业动态 更新时间:2024-10-10 09:17:47
本文介绍了视频自动播放功能无法在Chrome和Safari浏览器中正常运行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在没有任何用户手势的情况下使视频自动播放.我知道,根据最近的Google和Apple网络视频政策,我们不能在没有用户手势的情况下自动播放具有音频的视频.但是,我看到的网站仍然可以在现代网络浏览器中自动播放视频.

I want to make the video autoplay without any user gesture in reactjs. I know as per recent google and apple web video policy we cannot autoplay a video having audio without user gesture.But i have seen few websites which still autoplays the video across modern web browsers also.

我在stackoverflow上遇到了许多与此问题相关的问题,但没有一个帮助我.

I came across many questions related to this issue on stackoverflow but none helped me.

这是我尝试过的.

尝试1.

<video id="miniVideo" preLoad="yes" autoPlay="autoplay" loop width="100%" height="auto" playsInline> <source src="/mini/video/cooper.mp4" type="video/mp4" /> <source src="/mini/video/cooper.webm" type="video/webm" /> </video>

尝试2.

<iframe playsInline id="miniVideo" src="/mini/video/cooper.mp4" width="100%" height="400px" allow="autoplay; fullscreen"></iframe>

尝试3.

脚本:

componentDidMount(){ var videoTimer = document.getElementById("miniVideo"); videoTimer.play(); }

HTML:

<video id="miniVideo" width="100%" height="100%"> <source src="/video/cooper.mp4" type="video/mp4" /> <p>This browser does not support the video element.</p> </video>

我们将非常感谢您的帮助.谢谢

Your help will be well appreciated.Thanks

推荐答案

我不确定Safari,但Chrome更改了自动播放政策.在这里查看: developers.google/web /updates/2017/09/autoplay-policy-changes

I am not sure about Safari but Chrome has changed the autoplay policy. Look here:developers.google/web/updates/2017/09/autoplay-policy-changes

为了自动播放,请添加归属于video标签的muted. 例如:

In order to autoplay, add muted attributed to video tag. For example:

import React, { Component } from 'react'; class Player extends Component { constructor(props) { super(props); this.state = { isVideoMuted: true }; } handleMuteState = () => { this.setState(prevState => ({ isVideoMuted: !prevState.isVideoMuted })); } render() { return ( <div> <video muted={this.state.isVideoMuted} src="./video.mp4" /> <button onClick={this.handleMuteState}>{this.state.isVideoMuted ? 'Unmute' : 'Mute'}</button > </div> ); } } export default Player;

更多推荐

视频自动播放功能无法在Chrome和Safari浏览器中正常运行吗?

本文发布于:2023-11-28 18:36:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643511.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:正常运行   自动播放   器中   功能   视频

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!