1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

update components

This commit is contained in:
Luke Pulverenti 2016-05-09 11:46:47 -04:00
parent da7682e530
commit f2b505a6fb
9 changed files with 106 additions and 67 deletions

View file

@ -63,9 +63,14 @@ class BufferController extends EventHandler {
ms.removeEventListener('sourceopen', this.onmso);
ms.removeEventListener('sourceended', this.onmse);
ms.removeEventListener('sourceclose', this.onmsc);
// unlink MediaSource from video tag
this.media.src = '';
this.media.removeAttribute('src');
try {
// unlink MediaSource from video tag
this.media.src = '';
this.media.removeAttribute('src');
} catch(err) {
logger.warn(`onMediaDetaching:${err.message} while unlinking video.src`);
}
this.mediaSource = null;
this.media = null;
this.pendingTracks = null;

View file

@ -20,7 +20,7 @@ class LevelController extends EventHandler {
destroy() {
if (this.timer) {
clearInterval(this.timer);
clearTimeout(this.timer);
this.timer = null;
}
this._manualLevel = -1;
@ -113,24 +113,27 @@ class LevelController extends EventHandler {
}
set level(newLevel) {
if (this._levels && this._levels.length > newLevel &&
(this._level !== newLevel || this._levels[newLevel].details === undefined)) {
this.setLevelInternal(newLevel);
let levels = this._levels;
if (levels && levels.length > newLevel) {
if (this._level !== newLevel || levels[newLevel].details === undefined) {
this.setLevelInternal(newLevel);
}
}
}
setLevelInternal(newLevel) {
let levels = this._levels;
// check if level idx is valid
if (newLevel >= 0 && newLevel < this._levels.length) {
if (newLevel >= 0 && newLevel < levels.length) {
// stopping live reloading timer if any
if (this.timer) {
clearInterval(this.timer);
clearTimeout(this.timer);
this.timer = null;
}
this._level = newLevel;
logger.log(`switching to level ${newLevel}`);
this.hls.trigger(Event.LEVEL_SWITCH, {level: newLevel});
var level = this._levels[newLevel];
var level = levels[newLevel];
// check if we need to load playlist for this level
if (level.details === undefined || level.details.live === true) {
// level not retrieved yet, or live playlist we need to (re)load it
@ -150,6 +153,9 @@ class LevelController extends EventHandler {
set manualLevel(newLevel) {
this._manualLevel = newLevel;
if (this._startLevel === undefined) {
this._startLevel = newLevel;
}
if (newLevel !== -1) {
this.level = newLevel;
}
@ -222,7 +228,7 @@ class LevelController extends EventHandler {
this._level = undefined;
// stopping live reloading timer if any
if (this.timer) {
clearInterval(this.timer);
clearTimeout(this.timer);
this.timer = null;
}
// redispatch same error but with fatal set to true
@ -234,16 +240,30 @@ class LevelController extends EventHandler {
}
onLevelLoaded(data) {
// check if current playlist is a live playlist
if (data.details.live && !this.timer) {
// if live playlist we will have to reload it periodically
// set reload period to playlist target duration
this.timer = setInterval(this.ontick, 1000 * data.details.targetduration);
}
if (!data.details.live && this.timer) {
// playlist is not live and timer is armed : stopping it
clearInterval(this.timer);
this.timer = null;
// only process level loaded events matching with expected level
if (data.level === this._level) {
let newDetails = data.details;
// if current playlist is a live playlist, arm a timer to reload it
if (newDetails.live) {
let reloadInterval = 1000*newDetails.targetduration,
curLevel = this._levels[data.level],
curDetails = curLevel.details;
if (curDetails && newDetails.endSN === curDetails.endSN) {
// follow HLS Spec, If the client reloads a Playlist file and finds that it has not
// changed then it MUST wait for a period of one-half the target
// duration before retrying.
reloadInterval /=2;
logger.log(`same live playlist, reload twice faster`);
}
// decrement reloadInterval with level loading delay
reloadInterval -= performance.now() - data.stats.trequest;
// in any case, don't reload more than every second
reloadInterval = Math.max(1000,Math.round(reloadInterval));
logger.log(`live playlist, reload in ${reloadInterval} ms`);
this.timer = setTimeout(this.ontick,reloadInterval);
} else {
this.timer = null;
}
}
}

View file

@ -55,12 +55,6 @@ class BufferHelper {
buffered2.push(buffered[i]);
}
}
// in case current position is located before buffered time ranges, report area as not buffered
if (buffered2.length && pos < buffered2[0].start) {
return {len: 0, start: pos, end: pos, nextStart : buffered2[0].start};
}
for (i = 0, bufferLen = 0, bufferStart = bufferEnd = pos; i < buffered2.length; i++) {
var start = buffered2[i].start,
end = buffered2[i].end;