a81238c7 by Gary Katsevman

Update HLS:

dispose tech, playlist loader
don't trigger loadedmetadata if there was an error
no need for duration update workarounds, add duration to tech
update all the tests
remove irrelevant tests
1 parent 73420aa6
......@@ -51,6 +51,7 @@
var
loader = this,
media,
mediaUpdateTimeout,
request,
haveMetadata = function(error, xhr, url) {
......@@ -88,7 +89,7 @@
// refresh live playlists after a target duration passes
if (!loader.media().endList) {
window.setTimeout(function() {
mediaUpdateTimeout = window.setTimeout(function() {
loader.trigger('mediaupdatetimeout');
}, refreshDelay);
}
......@@ -104,6 +105,13 @@
loader.state = 'HAVE_NOTHING';
loader.dispose = function() {
if (request) {
request.abort();
}
window.clearTimeout(mediaUpdateTimeout);
};
/**
* When called without any arguments, returns the currently
* active media playlist. When called with a single argument,
......@@ -213,7 +221,9 @@
haveMetadata(error,
this,
parser.manifest.playlists[0].uri);
if (!error) {
loader.trigger('loadedmetadata');
}
});
return loader.trigger('loadedplaylist');
}
......
......@@ -153,6 +153,12 @@ var
var
duration = 0,
segment,
i;
if (!playlist) {
return 0;
}
i = (playlist.segments || []).length;
// if present, use the duration specified in the playlist
......@@ -205,16 +211,8 @@ var
* Update the player duration
*/
updateDuration = function(playlist) {
var tech;
// update the duration
player.duration(totalDuration(playlist));
// tell the flash tech of the new duration
tech = player.el().querySelector('.vjs-tech');
if(tech.vjs_setProperty) {
tech.vjs_setProperty('duration', player.duration());
}
// manually fire the duration change
player.trigger('durationchange');
};
/**
......@@ -310,7 +308,8 @@ var
}
// if no segments are available, do nothing
if (!player.hls.playlists.media().segments) {
if (player.hls.playlists.state === "HAVE_NOTHING" ||
!player.hls.playlists.media().segments) {
return;
}
......@@ -456,12 +455,12 @@ videojs.Hls = videojs.Flash.extend({
source = options.source,
settings = player.options();
player.hls = this;
delete options.source;
options.swf = settings.flash.swf;
videojs.Flash.call(this, player, options, ready);
player.hls = {};
options.source = source;
videojs.Hls.prototype.src.call(player, options.source && options.source.src);
videojs.Hls.prototype.src.call(this, options.source && options.source.src);
}
});
......@@ -472,7 +471,7 @@ videojs.Hls.prototype.src = function(src) {
source;
if (src) {
mediaSource = new videojs.MediaSource(),
mediaSource = new videojs.MediaSource();
source = {
src: videojs.URL.createObjectURL(mediaSource),
type: "video/flv"
......@@ -480,10 +479,25 @@ videojs.Hls.prototype.src = function(src) {
player.hls.mediaSource = mediaSource;
initSource(player, mediaSource, src);
this.ready(function() {
this.el().querySelector('.vjs-tech').vjs_src(source.src);
this.el().vjs_src(source.src);
});
}
}
};
videojs.Hls.prototype.duration = function() {
var playlists = this.player().hls.playlists;
if (playlists) {
return totalDuration(playlists.media());
}
return 0;
};
videojs.Hls.prototype.dispose = function() {
if (this.player().hls.playlists) {
this.player().hls.playlists.dispose();
}
videojs.Flash.prototype.dispose.call(this);
};
//for (var prop in videojs.Flash) {
//videojs.Hls[prop] = videojs.Flash[prop];
......
......@@ -15,7 +15,7 @@
<script src="../libs/qunit/qunit.js"></script>
<!-- video.js -->
<script src="../node_modules/video.js/dist/video-js/video.dev.js"></script>
<script src="../node_modules/video.js/dist/video-js/video.js"></script>
<script src="../node_modules/videojs-contrib-media-sources/src/videojs-media-sources.js"></script>
<!-- HLS plugin -->
......