2015-05-05 87 views
0

我正在Squarespace网站上工作,他们不允许视频上传,因此我使用Dropbox来托管视频。从Dropbox使用HTML5视频播放器的MP4,不重复

视频开始播放,但他没有重复。

这是代码:

<video id="htmlVideo" loop="loop"> 
    <source type="video/mp4" src="https://www.dropbox.com/s/videoID/videoplayback.mp4?dl=1"> 
</video> 

可能是什么问题呢?

这是我如何创建视频

/* 
function repeatForDropbox() { 
    console.log("repeatForDropbox caled" + htmlVideo); 
} 
*/ 

function createVideo() { 
    var video = document.createElement("video"); 
     video.id = "htmlVideo"; 
     video.loop = "loop"; 

    var vidSource = document.createElement("source"); 
     vidSource.type = "video/mp4"; 
     vidSource.src = "https://www.dropbox.com/s/videoID/videoplayback.mp4?dl=1"; 

    video.appendChild(vidSource); 

    var vidLocation = document.querySelector('#location').parentNode; 
     vidLocation.appendChild(video); 
    htmlVideo = document.querySelector(" #htmlVideo "); 

    // on load, play the video/mp4 
    window.onload = function() { 
     setTimeout(function() { 
      htmlVideo.play(); 
      // htmlVideo.addEventListener("ended", repeatForDropbox);           
      // I tried here to make the video repeat, using the "ended" event listener 
      // so when the video ended, the video 
      // should get another <source> element(same src) 
      // and delete the old one 
      // but the event didn't fire 
      // I also tried htmlVideo.onended = function() {} , but same result 
     }, 500); 
    } 
} 
+0

您试图更改'loop =“loop”'为:'

+0

@Ferrrmolina,我怎么用Javascript做到这一点?只添加“循环”。 – Marian07

+0

在html标记中。 – Ferrrmolina

回答

1

只是一个猜测,但我怀疑这涉及到重定向。一个带有?dl = 1的Dropbox共享链接会将您重定向到一次性使用 URL来下载内容。也许当视频播放器尝试循环时,它会尝试再次访问重定向的目标。

这可能会出现在来自浏览器的网络流量中,所以值得一看。 (例如,如果您使用的是Chrome浏览器的网络选项卡)。

+0

我很害怕这个。我认为这就是为什么视频不会重复。您怎么看待替换元素?这会使视频再次播放吗?或者不是,因为曾经被称为。 – Marian07

0

万一还有人需求的解决方案,我发现使用jQuery解决方法:

$('video').on('ended', function() { 
    this.load(); 
    this.play(); 
}); 

然而,有一个重复之间的轻微延迟!