gpt4 book ai didi

google-chrome - 强制使用Javascript完整地预加载HTML5视频?

转载 作者:行者123 更新时间:2023-12-03 14:59:05 25 4
gpt4 key购买 nike

我将尝试以HTML5完全预载视频。我使用属性preload=auto,但它不会预加载整个视频...在Chrome中,视频仅预加载2%,在Safari中预加载大约50%...

是否可以使用javascript强制播放完整的预加载视频?

最佳答案

function addSourceToVideo(element, src, type) {    
var source = document.createElement('source');
source.src = src;
source.type = type;
element.appendChild(source);
}

var video;
$(document).ready(function(){
video = document.getElementsByTagName('video')[0];
addSourceToVideo( video, "http://your-server.com/clip.ogv", "video/ogv");
addSourceToVideo( video, "http://your-server.com/clip.mp4", "video/mp4");
video.addEventListener("progress", progressHandler,false);
});

progressHandler = function(e) {
if( video.duration ) {
var percent = (video.buffered.end(0)/video.duration) * 100;
console.log( percent );
if( percent >= 100 ) {
console.log("loaded!");
}
video.currentTime++;
}
}

关于google-chrome - 强制使用Javascript完整地预加载HTML5视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16581801/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com