【问题标题】:autoPlay background video doesn't render on mobile自动播放背景视频无法在移动设备上呈现
【发布时间】:2019-12-20 08:48:36
【问题描述】:

我正在开发一个 React 网站,并且我正在为主页使用视频背景,它在桌面版本中完美运行,但视频根本无法在移动设备上呈现

video 标签已经包含 autoPlay 和 mute 属性,我添加了 playInline 但仍然没有任何反应

这里是html代码:

<header className="v-header container">
                <div className="fullscreen-video-wrap">
                    <video src={code} autoPlay muted loop playsInline type="video/mp4"></video>
                </div>
                <div className="header-overlay"></div>
                <div className="header-content text-md-center">
                    <h1>Night'Art+</h1>
                    <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Id temporibus perferendis necessitatibus numquam amet impedit explicabo? Debitis quasi ullam aperiam!</p>
                    <Button inverted basic size='massive'>Join us</Button>
                </div>
            </header>

和css代码:


  .v-header{
    height:100vh;
    display:flex;
    align-items:center;
    color:#fff;
  }

  .container{
    max-width:960px;
    padding-left:1rem;
    padding-right:1rem;
    margin:auto;
    text-align:center;
  }

  .fullscreen-video-wrap{
    position:absolute;
    top:0;
    left:0;
    width:100%;
    height:100vh;
    overflow:hidden;
  }

  .fullscreen-video-wrap video{
    min-height:100%;
    min-width:100%;
  }

  .header-overlay{
    height:100vh;
    position: absolute;
    top:0;
    left:0;
    width:100vw;
    z-index:1;
    background-image: linear-gradient(to right, #4300ab, #ff0a6c);
    opacity:0.7;
  }

  .header-content{
    z-index:2;
    justify-content: center;
  }

  .header-content h1{
    font-size:50px;
    margin-bottom:0;
  }

  .header-content p{
    font-size:1.5rem;
    display:block;
  }

【问题讨论】:

标签: reactjs


【解决方案1】:

根据this site,移动设备需要满足一些条件才能允许自动播放(视频大小、用户手势、音轨等)。大多数浏览器都会考虑用户的数据消耗。更多信息here。如果您提供链接和您的设备规格,我可以进行更多研究。

【讨论】:

猜你喜欢
  • 2020-02-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-08
  • 2021-09-03
  • 1970-01-01
  • 2019-11-14
  • 2013-09-06
相关资源
最近更新 更多