af5bb890 by David LaPalomento

Put HLS at the front of the techOrder by default. Make the tech a no-op if HLS i…

…s supported natively.
Update the default techOrder to include HLS support first when the plugin is loaded. Prefer HTML5 implementations if they're available. Added tests to verify both constraints.
1 parent 33fcf898
......@@ -595,6 +595,26 @@ videojs.Hls = videojs.Flash.extend({
}
});
/**
* Whether the browser has built-in HLS support.
*/
videojs.Hls.supportsNativeHls = (function() {
var
video = document.createElement('video'),
xMpegUrl,
vndMpeg;
// native HLS is definitely not supported if HTML5 video isn't
if (!videojs.Html5.isSupported()) {
return false;
}
xMpegUrl = video.canPlayType('application/x-mpegURL');
vndMpeg = video.canPlayType('application/vnd.apple.mpegURL');
return (/probably|maybe/).test(xMpegUrl) ||
(/probably|maybe/).test(vndMpeg);
})();
// the desired length of video to maintain in the buffer, in seconds
videojs.Hls.GOAL_BUFFER_LENGTH = 30;
......@@ -628,7 +648,9 @@ videojs.Hls.prototype.duration = function() {
};
videojs.Hls.isSupported = function() {
return videojs.Flash.isSupported() && videojs.MediaSource;
return !videojs.Hls.supportsNativeHls &&
videojs.Flash.isSupported() &&
videojs.MediaSource;
};
videojs.Hls.canPlaySource = function(srcObj) {
......@@ -757,6 +779,6 @@ resolveUrl = videojs.Hls.resolveUrl = function(basePath, path) {
};
// Add HLS to the standard tech order
videojs.options.techOrder.push('hls');
videojs.options.techOrder.unshift('hls');
})(window, window.videojs, document);
......
......@@ -28,6 +28,7 @@ var
oldSetTimeout,
oldSourceBuffer,
oldFlashSupported,
oldNativeHlsSupport,
requests,
xhr,
......@@ -39,7 +40,6 @@ var
flash: {
swf: ''
},
techOrder: ['hls'],
hls: options || {}
});
......@@ -125,6 +125,8 @@ module('HLS', {
oldSegmentParser = videojs.Hls.SegmentParser;
oldSetTimeout = window.setTimeout;
oldNativeHlsSupport = videojs.Hls.supportsNativeHls;
// fake XHRs
xhr = sinon.useFakeXMLHttpRequest();
requests = [];
......@@ -141,6 +143,7 @@ module('HLS', {
videojs.Flash.isSupported = oldFlashSupported;
videojs.MediaSource.open = oldMediaSourceOpen;
videojs.Hls.SegmentParser = oldSegmentParser;
videojs.Hls.supportsNativeHls = oldNativeHlsSupport;
videojs.SourceBuffer = oldSourceBuffer;
window.setTimeout = oldSetTimeout;
xhr.restore();
......@@ -1207,4 +1210,21 @@ test('only supports HLS MIME types', function() {
}), 'does not support flv');
});
test('adds Hls to the default tech order', function() {
strictEqual(videojs.options.techOrder[0], 'hls', 'first entry is Hls');
});
test('has no effect if native HLS is available', function() {
var player;
videojs.Hls.supportsNativeHls = true;
player = createPlayer();
player.src({
src: 'http://example.com/manifest/master.m3u8',
type: 'application/x-mpegURL'
});
ok(!player.hls, 'did not load hls tech');
player.dispose();
});
})(window, window.videojs);
......