移动设备上无法播放背景视频?

4
我已经制作了一个落地页,在表单的背景上播放视频。
在桌面上一切正常,但我使用Chrome检查了我的Android设备,背景视频无法播放。
有人能帮我解决这个问题吗?
这是我的链接
HTML:
   <p>
<video autoplay="" id="video" loop=""><source src="http://www.mygreencity.in/Enquiry.mp4" type="video/webm" /> <source src="Enquiry.mp4" type="video/mp4" /></video>
</p>  

<form action="" class="form" method="post">


<p><input name="enq_name" placeholder="Full Name" required="" type="text" autocomplete="off" alt="Full Name" title="Full Name"/></p>

<p><input name="enq_mobile" placeholder="Mobile Number" required="" type="number" autocomplete="off" alt="Number" title="Number"/></p>

<p><input name="enq_email" placeholder="Email" required="" type="email" autocomplete="off" alt="Email ID" title="Email ID"/></p>
<input class="button button-block" name="enq_submit" type="submit" value="Go To Site" alt="Go To Site" title="Go To Site"/></form>

CSS:

    *, *:before, *:after {
  box-sizing: border-box;
}

html {
  overflow-y: scroll;
}

body {
  background: #fff;
  font-family: 'Titillium Web', sans-serif;
}

a {
  text-decoration: none;
  color: #1ab188;
  -webkit-transition: .5s ease;
          transition: .5s ease;
}
a:hover {
  color: #179b77;
}

.form {
  background: rgba(19, 35, 47, 0.9);
  padding: 40px;
  max-width: 600px;
  margin: 80px auto;

  border-radius: 4px;
  box-shadow: 0 4px 10px 4px rgba(19, 35, 47, 0.3);
}


h1 {
  text-align: center;
  color: #ffffff;
  font-weight: 300;
  margin: 0 0 40px;
}

label {
  position: absolute;
  -webkit-transform: translateY(6px);
      -ms-transform: translateY(6px);
          transform: translateY(6px);
  left: 13px;
  color: rgba(255, 255, 255, 0.5);
  -webkit-transition: all 0.25s ease;
          transition: all 0.25s ease;
  -webkit-backface-visibility: hidden;
  pointer-events: none;
  font-size: 22px;
}

input, textarea {

  font-size: 22px;
  display: block;
  width: 100%;
  height: 100%;
  padding: 5px 10px;
  background: none;
  background-image: none;
  border: 1px solid #a0b3b0;
  color: #ffffff;
  border-radius: 0;
  -webkit-transition: border-color .25s ease, box-shadow .25s ease;
          transition: border-color .25s ease, box-shadow .25s ease;
}
input:focus, textarea:focus {
  outline: 0;
  border-color: #1ab188;
}

textarea {
  border: 2px solid #a0b3b0;
  resize: vertical;
}


.button {
  border: 0;
  outline: none;
  border-radius: 0;
  padding: 15px 0;
  font-size: 2rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .1em;
  background: #1ab188;
  color: #ffffff;
  -webkit-transition: all 0.5s ease;
          transition: all 0.5s ease;
  -webkit-appearance: none;
}
.button:hover, .button:focus {
  background: #179b77;
}

.button-block {
  display: block;
  width: 100%;
}

.forgot {
  margin-top: -20px;
  text-align: right;
}

p {
margin-bottom: 40px;
}


video { 
    position: fixed;
    top: 50%;
    left: 50%;
    min-width: 100%;
    min-height: 100%;
    width: auto;
    height: auto;
    z-index: -100;
    transform: translateX(-50%) translateY(-50%);
  background: #fff;
  background-size: cover;
  transition: 1s opacity;
}

div{
margin:20px;
}

input[type=number]::-webkit-inner-spin-button, 
input[type=number]::-webkit-outer-spin-button { 
  -webkit-appearance: none; 
  margin: 0; 
}

input[type=number] {
-moz-appearance: textfield;
}

Chrome for Android以及大多数移动平台上都禁用了自动播放视频。 - Andrew Staker
3个回答

12
你的视频元素需要添加更多属性。
<video autoplay loop muted playsinline id="video-background" poster="images/poster.jpg">

移动设备上的Safari和Chrome对移动视频的播放方式进行了更改。默认情况下,只有在视频静音时才能自动播放。但对于webkit/iOs,您还需要第二个属性;playsinline。该属性使其内联播放,而不是跳转到全屏视频。

如果您的目标是iOS 11,请确保您的移动设备没有运行在低功耗模式下。如果您使用的是Chrome for Android,则数据节省模式也会阻止自动播放,并因此不显示视频。这方面没有解决办法。


谢谢 - "autoplay loop muted playsinline" 已经生效。 - bbidadi
对我来说也可以运行。 - user3388384
对我也一样!谢谢你! - Erikamyself
2
你是指出低功耗模式问题的人!!!谢谢。 - Fewture Webdesign
我今天尝试了一下,对我来说有效。 - Patrick
运行得很顺利。此外,在React中,这个属性应该是驼峰命名法,即playsInline - undefined

4
CSS(层叠样式表):
#section-video video {
   display: block; 
}

在相应的CSS文件中,将"display:none"替换为"display:block"。

这对我来说是解决方案 :) - yush

4
你应该查看这种jQuery插件。此外,除了只有.mp4格式,你还应该提供一些.webm.ogv格式的替代方案,以便在浏览器和设备上具有更好的兼容性。你还应该像下面的例子中的poster="videos/poster.png"一样拥有一个“回退”图像。如果这些格式都不适用于所使用的浏览器/平台,则显示此图像而不是视频。你需要将你的视频转换为.webm.ogv格式。由于我自己仍在寻找一个好的转换工具(没有额外的丑陋横幅等),因此无法给你提供建议。
<video id="bgVideo" autoplay poster="videos/poster.png">
    <source src="http://www.mygreencity.in/Enquiry.mp4" type="video/mp4"/>
    <source src="http://www.mygreencity.in/Enquiry.webm" type="video/webm"/>
    <source src="http://www.mygreencity.in/Enquiry.ogv" type="video/ogg"/>    
</video>

祝你好运


我的问题是在安卓设备上无法播放MP4文件,所以我不得不使用WebM格式。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接