如何自动播放来自Android的视频

时间:2018-07-29 18:27:48

标签: reactjs html5-video

我想显示行为类似于gif(自动播放且无控件)的视频。该代码在PC浏览器中确实能很好地工作,但是不幸的是,该视频无法在最新的android chrome浏览器中自动播放。

import React, { Component } from 'react'

import "css/MotionLogo.css"
import bumperLandscapeMp4 from '../../assets/home/bumper_landscape.mp4'

class MotionLogo extends Component {    
  render() {
    return (
      <section className="mlogo">
        <video
          className="mlogo__video"
          muted
          autoPlay
        >
          <source type='video/mp4' src={bumperLandscapeMp4} />
            Sorry, your browser doesn't support embedded videos.
        </video>
      </section>
    )
  }
}

export default MotionLogo

我在这里反应时遇到了一个问题 https://github.com/facebook/react/issues/6544https://github.com/facebook/react/issues/10389

如果该视频未静音,浏览器将不会自动播放视频,但是根据我的反应,该静音属性仍然存在问题

我正在使用的另一种方法

  1. 在视频上使用ref并在componentDidMount()上触发它以自动播放
  2. 使用危险地设置内部HTML设置内部视频
  3. 使用此库https://github.com/DylanVann/react-video-tag
  4. 使用视频参考手动设置setAttribute值

所有这些都始终在PC上运行,但在我的android浏览器上仍然不运行。也许这种方法仅适用于iOS?

当我尝试向视频中添加控件时,单击它们即可播放视频。因此问题出在自动播放中。

0 个答案:

没有答案
相关问题