better buffering
This commit is contained in:
parent
b3a73dedbf
commit
cf3f3c4103
1 changed files with 25 additions and 7 deletions
|
@ -165,15 +165,33 @@ Ox.VideoElement = function(options, self) {
|
||||||
},
|
},
|
||||||
progress: function() {
|
progress: function() {
|
||||||
// stop buffering if buffered to end point
|
// stop buffering if buffered to end point
|
||||||
if (self.video == this && self.buffering) {
|
var video = this,
|
||||||
var item = self.items[self.currentItem];
|
item = self.items[self.currentItem],
|
||||||
Ox.range(self.video.buffered.length).forEach(function(i) {
|
nextItem = Ox.mod(self.currentItem + 1, self.numberOfItems),
|
||||||
if (self.video.buffered.start(i) <= item['in']
|
next = self.items[nextItem],
|
||||||
|
nextVideo = self.$videos[Ox.mod(self.currentVideo + 1, self.$videos.length)][0];
|
||||||
|
if (self.video == video && (video.preload != 'none' || self.buffering)) {
|
||||||
|
if (clipCached(video, item)) {
|
||||||
|
self.video.preload = 'none';
|
||||||
|
self.buffering = false;
|
||||||
|
if (nextVideo != self.video) {
|
||||||
|
nextVideo.preload = 'auto';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (!self.buffering && nextVideo == video && video.preload != 'none') {
|
||||||
|
if (clipCached(video, next)) {
|
||||||
|
video.preload = 'none';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function clipCached(video, item) {
|
||||||
|
var cached = false
|
||||||
|
Ox.range(video.buffered.length).forEach(function(i) {
|
||||||
|
if (video.buffered.start(i) <= item['in']
|
||||||
&& self.video.buffered.end(i) >= item.out) {
|
&& self.video.buffered.end(i) >= item.out) {
|
||||||
self.video.preload = 'none';
|
cached = true
|
||||||
self.buffering = false;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
return cached
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
seeking: function() {
|
seeking: function() {
|
||||||
|
@ -358,8 +376,8 @@ Ox.VideoElement = function(options, self) {
|
||||||
if (self.$video.attr('src') != item.src) {
|
if (self.$video.attr('src') != item.src) {
|
||||||
self.loadedMetadata && Ox.Log('Video', 'caching next item failed, reset src');
|
self.loadedMetadata && Ox.Log('Video', 'caching next item failed, reset src');
|
||||||
self.video.src = item.src;
|
self.video.src = item.src;
|
||||||
self.video.preload = 'auto';
|
|
||||||
}
|
}
|
||||||
|
self.video.preload = 'auto';
|
||||||
self.video.volume = getVolume();
|
self.video.volume = getVolume();
|
||||||
self.video.playbackRate = self.options.playbackRate;
|
self.video.playbackRate = self.options.playbackRate;
|
||||||
self.$video.css(css);
|
self.$video.css(css);
|
||||||
|
|
Loading…
Reference in a new issue