简体   繁体   English

与HTML5视频播放器一起使用的Dropbox的mp4,不再重复

[英]Mp4 from Dropbox used with HTML5 video player, is not repeating

I'm working on a Squarespace website, and they don't allow video upload, so I'm using Dropbox to host a video. 我在Squarespace网站上工作,并且他们不允许视频上传,所以我正在使用Dropbox托管视频。

The video starts playing, but he is not repeating. 视频开始播放,但他没有重复。

This is the code: 这是代码:

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

What could be the problem? 可能是什么问题呢?

This is how I create the 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);
    }
}

Just a guess, but I suspect this relates to redirects. 只是一个猜测,但我怀疑这与重定向有关。 A Dropbox share link with ?dl=1 on it will redirect you to a one-time use URL to download the content. 带有?dl = 1的Dropbox共享链接会将您重定向到一次性使用的 URL,以下载内容。 Perhaps when the video player tries to loop, it tries to access the target of the redirect again. 也许当视频播放器尝试循环播放时,它会尝试再次访问重定向目标。

This might show up in the network traffic from the browser, so it's worth taking a look. 这可能会显示在浏览器的网络流量中,因此值得一看。 (Eg the network tab of Chrome inspector, if you're using Chrome.) (如果您使用的是Chrome,例如,Chrome检查器的“网络”标签。)

I would see if squarespace will let you save the binary of the video into a text file and then import it with AJAX and save it to indexedDB before converting it to video. 我想知道Squarespace是否可以让您将视频的二进制文件保存到文本文件中,然后使用AJAX导入并将其保存到indexedDB,然后再将其转换为视频。

Here's some links: 这里是一些链接:

Display a video from a Blob Javascript 显示来自Blob Javascript的视频

https://simpl.info/video/offline/ https://simpl.info/video/offline/

Just in case anyone still needs the solution, I found a workaround using jQuery: 万一有人仍然需要该解决方案,我找到了一种使用jQuery的解决方法:

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

However, there is a slight delay between repeats! 但是,重复之间会稍有延迟!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM