Mp4没有在Chrome中自动播放,在Firefox中运行良好

时间:2016-03-10 21:35:43

标签: html google-chrome video mp4 autoplay

以下是实际网站:nonbinaryassembly.com

这是我的代码:

<video id='second_slider_image' autoplay loop width="100%" alt='second_slider_image'>
        <source src="http://nonbinaryassembly.com/wp-content/uploads/2016/03/000652895-aerial-view-city-skyscrapers.mp4" type="video/mp4">
</video>

有什么想法吗?

2 个答案:

答案 0 :(得分:0)

我认为在Chrome中你必须将其设置为autoplay = true。你试过了吗?

答案 1 :(得分:0)

我从未弄清楚为什么它没有正常运行(我最终删除了自动播放因此它不再存在),所以我提出了一个使用JS的OK解决方案:

<video id="USTC" width="100%" src="http://URL/video1.mp4" type='video/mp4' onmouseenter="play_if_stopped();" onended="slider_run();">

video_count =1;
videoPlayer = document.getElementById("uniqueID");
Object.defineProperty(HTMLMediaElement.prototype, 'playing', {
    get: function(){
        return (!this.paused && !this.ended && this.readyState > 2);
    }
});

function play_if_stopped() {
  if(document.querySelector('#uniqueID').playing){ // checks if element is playing right   now
    console.log("playing");
  } else {
    videoPlayer.play();
    console.log("started");
  }
};


function slider_run(){
  video_count++;
  if (video_count == 3) video_count =1;
  var nextVideo = "http://URL/"+video_count+".mp4";
  videoPlayer.src = nextVideo;
  videoPlayer.play();
};