1
0
mirror of https://github.com/videojs/video.js.git synced 2024-12-25 02:42:10 +02:00

Fixed type support checking for an empty src string. closes #1797

This commit is contained in:
heff 2015-01-16 11:42:27 -08:00
parent a3b12d9d03
commit e8235c9022
3 changed files with 36 additions and 5 deletions

View File

@ -2,7 +2,8 @@ CHANGELOG
=========
## HEAD (Unreleased)
* Exported missing source handler functions ([view](https://github.com/videojs/video.js/pull/1787))
* @heff exported missing source handler functions ([view](https://github.com/videojs/video.js/pull/1787))
* @heff fixed type support checking for an empty src string ([view](https://github.com/videojs/video.js/pull/1797))
--------------------

View File

@ -307,13 +307,13 @@ vjs.Html5.nativeSourceHandler = {};
* @return {String} 'probably', 'maybe', or '' (empty string)
*/
vjs.Html5.nativeSourceHandler.canHandleSource = function(source){
var ext;
var match, ext;
function canPlayType(type){
// IE9 on Windows 7 without MediaPlayer throws an error here
// https://github.com/videojs/video.js/issues/519
try {
return !!vjs.TEST_VID.canPlayType(type);
return vjs.TEST_VID.canPlayType(type);
} catch(e) {
return '';
}
@ -322,11 +322,15 @@ vjs.Html5.nativeSourceHandler.canHandleSource = function(source){
// If a type was provided we should rely on that
if (source.type) {
return canPlayType(source.type);
} else {
} else if (source.src) {
// If no type, fall back to checking 'video/[EXTENSION]'
ext = source.src.match(/\.([^\/\?]+)(\?[^\/]+)?$/i)[1];
match = source.src.match(/\.([^\/\?]+)(\?[^\/]+)?$/i);
ext = match && match[1];
return canPlayType('video/'+ext);
}
return '';
};
/**

View File

@ -134,3 +134,29 @@ test('error events may not set the errors property', function() {
test('should have the source handler interface', function() {
ok(vjs.Html5.registerSourceHandler, 'has the registerSourceHandler function');
});
test('native source handler canHandleSource', function(){
var result;
// Stub the test video canPlayType (used in canHandleSource) to control results
var origCPT = vjs.TEST_VID.canPlayType;
vjs.TEST_VID.canPlayType = function(type){
if (type === 'video/mp4') {
return 'maybe';
}
return '';
};
var canHandleSource = vjs.Html5.nativeSourceHandler.canHandleSource;
equal(canHandleSource({ type: 'video/mp4', src: 'video.flv' }), 'maybe', 'Native source handler reported type support');
equal(canHandleSource({ src: 'http://www.example.com/video.mp4' }), 'maybe', 'Native source handler reported extension support');
// Test for issue videojs/video.js#1785 and other potential failures
equal(canHandleSource({ src: '' }), '', 'Native source handler handled empty src');
equal(canHandleSource({}), '', 'Native source handler handled empty object');
equal(canHandleSource({ src: 'foo' }), '', 'Native source handler handled bad src');
equal(canHandleSource({ type: 'foo' }), '', 'Native source handler handled bad type');
// Reset test video canPlayType
vjs.TEST_VID.canPlayType = origCPT;
});