39606acc by Tom Johnson

Merge pull request #94 from videojs/feature/auto-tech-order

Rebased update-options
2 parents aecdda0d af5bb890
......@@ -12,11 +12,8 @@ Download the [Media Source plugin](https://github.com/videojs/videojs-contrib-me
<script src="videojs-media-sources.js"></script>
<script src="videojs-hls.min.js"></script>
<script>
var player = videojs('test-vid', {
techOrder: ['html5', 'hls', 'flash']
}, function() {
this.play();
});
var player = videojs('test-vid');
player.play();
</script>
```
......@@ -60,7 +57,6 @@ other tech:
```javascript
videojs(video, {
techOrder: ['hls'],
hls: {
withCredentials: true
}
......
......@@ -63,12 +63,7 @@
<script>
videojs.options.flash.swf = 'node_modules/video.js/dist/video-js/video-js.swf';
// initialize the player
var player = videojs('video', {
techOrder: ['hls']
});
// initialize the plugin
//player.hls()
var player = videojs('video');
</script>
</body>
</html>
......
......@@ -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) {
......@@ -756,4 +778,7 @@ resolveUrl = videojs.Hls.resolveUrl = function(basePath, path) {
return result;
};
// Add HLS to the standard tech order
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);
......