我尝试使用javascript更改视频源,并将currentTime设置为src更改时的时间,但我在Chrome上显示黑屏并在Firefox中显示一个带有奇怪声音的冻结屏幕,就像我更改src一样。如果我删除
$("#video").on("canplay",function(){
video.currentTime = time;
});
它工作正常。
<video src="http://srv35.clipconverter.cc/download/tdCQhWZj2IqwZGpolpWUaXFk5KWmqWxt4pSXaWlmnGhkZnK0qc%2FMqHyf1qiZpa2d2A%3D%3D/Blunt%20%26%20Real%20ft.%20Ledri%20Vula%20-%20Nese%20m%27don%20ti%20-%20Remix%20%28Official%20Video%20HD%29.mp4" id="video" autoplay></video>
<div id="360p" class="quality">360p</div>
var video = document.getElementById('video');
var time;
var _360p = "http://r3---sn-p5qlsnel.googlevideo.com/videoplayback?ratebypass=yes&sparams=id,initcwndbps,ip,ipbits,itag,mime,mm,ms,mv,ratebypass,source,upn,expire&ipbits=0&mt=1410631565&sver=3&itag=18&expire=1410653286&mm=31&upn=vTh5FN82i_U&id=o-AJXkFxYoWM1bFEPoTrX53eNVZbgtwutGGXv655WRWj4Q&mime=video/mp4&initcwndbps=1202000&ip=2001:41d0:2:40c5:a8b1:cb97:ef0b:b1b4&key=yt5&fexp=900147,927622,931983,932404,934030,936117,945539,946023,947209,952302,953801&source=youtube&mv=m&ms=au&signature=A77C56E95778206A0A06799B860CECFAE8A35ED8.C27AA1B748D371DFCC52DA1219133F63FDBDABB4&&title=Blunt+%26+Real+ft.+Ledri+Vula+-+Nese+m%27don+ti+-+Remix+%28Official+Video+HD%29";
var _1080p = "http://srv35.clipconverter.cc/download/tdCQhWZj2IqwZGpolpWUaXFk5KWmqWxt4pSXaWlmnGhkZnK0qc%2FMqHyf1qiZpa2d2A%3D%3D/Blunt%20%26%20Real%20ft.%20Ledri%20Vula%20-%20Nese%20m%27don%20ti%20-%20Remix%20%28Official%20Video%20HD%29.mp4";
video.addEventListener("timeupdate", function() {
time = video.currentTime;
});
$("#360p").click(function() {
$("#preload").attr("src", _360p)
$("#preload").on("canplay",function(){
$('#video').attr("src", _360p);
$("#video").on("canplay",function(){
video.currentTime = time;
});
});
});
答案 0 :(得分:1)
设置video.src和video.currentTime可能会导致调用timeupdate和canplay处理程序。我想你想在设置video.src之前取消注册timeupdate处理程序,并可能在设置video.currentTime之前取消注册video.oncanplay处理程序。 (我无法在你的jsfiddle中测试这个,因为googlevideo网址会返回403 Forbidden。)