在其他4个主要浏览器(Chrome,Firefox,IE和Safari)上,readyState变为4,我的代码执行得很好。但是在Opera上,readyState仅达到2,而从未达到4。
码:
var createSeekslider = function() {
if($atVideo[0].readyState == 4) {
var videoDuration = $atVideo[0].duration;
$seekSlider = $('.videoSeekslider').slider({
orientation:'horizontal',
range:'min',
min:0,
max:videoDuration,
value:0,
step:0.01,
animate:true,
slide: function(event, ui) {
$atVideo[0].currentTime = ui.value;
}
}); //End of (seekslider).slider function
} else {
setTimeout(createSeekslider, 150);
}
}
createSeekslider();
任何帮助将不胜感激!!
最佳答案
我不建议捕获readyState
等于4的瞬间,而是建议略有不同的策略-处理canplaythrough
事件:
$atVideo[0].addEventListener('canplaythrough', function() {
// actually, `$atVideo[0].oncanplaythrough = function()` should do fine too
$seekSlider = $('.videoSeekslider').slider({
orientation: 'horizontal',
range: 'min',
min: 0,
max: this.duration,
value: 0,
step: 0.01,
animate: true,
slide: (function(event, ui) {
this.currentTime = ui.value;
}).bind(this)
});
});
我怀疑您的问题与this issue中所述的问题相同:简而言之,Opera在开始加载视频后立即将
readyState
设置为4(HAVE_ENOUGH_DATA
),然后在某些情况下将其切换为2(HAVE_CURRENT_DATA
)它的很大一部分已加载-对于setTimeout
安排的检查来说,这太快了。关于javascript - Opera HTML5视频readyState == 2而不是等于4,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22792507/