mirror of
https://github.com/videojs/video.js.git
synced 2025-07-03 00:57:02 +02:00
+ vjs.Html5.{patchCanPlayType,unpatchCanPlayType}
patchCanPlayType is called on load. It patched video#canPlayType if needed. unpatchCanPlayType will revert the patch and return the patch function. There are also corresponding tests that test patchCanPlayType, unpatchCanPlayType and also whether the patch functions themselves work correctly.
This commit is contained in:
@ -266,6 +266,55 @@ vjs.Html5.canControlVolume = function(){
|
||||
return volume !== vjs.TEST_VID.volume;
|
||||
};
|
||||
|
||||
// HTML5 Feature detection and Device Fixes --------------------------------- //
|
||||
(function() {
|
||||
var canPlayType,
|
||||
mpegurlRE = /^application\/(?:x-|vnd\.apple\.)mpegurl$/i,
|
||||
mp4RE = /^video\/mp4$/i;
|
||||
|
||||
vjs.Html5.patchCanPlayType = function() {
|
||||
// Android 4.0 and above can play HLS to some extent but it reports being unable to do so
|
||||
if (vjs.ANDROID_VERSION >= 4.0) {
|
||||
if (!canPlayType) {
|
||||
canPlayType = HTMLVideoElement.prototype.canPlayType;
|
||||
}
|
||||
|
||||
HTMLVideoElement.prototype.canPlayType = function(type) {
|
||||
if (type && mpegurlRE.test(type)) {
|
||||
return "maybe";
|
||||
}
|
||||
return canPlayType.call(this, type);
|
||||
};
|
||||
}
|
||||
|
||||
// Override Android 2.2 and less canPlayType method which is broken
|
||||
if (vjs.IS_OLD_ANDROID) {
|
||||
if (!canPlayType) {
|
||||
canPlayType = HTMLVideoElement.prototype.canPlayType;
|
||||
}
|
||||
|
||||
HTMLVideoElement.prototype.canPlayType = function(type){
|
||||
if (type && mp4RE.test(type)) {
|
||||
return "maybe";
|
||||
}
|
||||
return canPlayType.call(this, type);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
vjs.Html5.unpatchCanPlayType = function() {
|
||||
var r = canPlayType;
|
||||
if (canPlayType) {
|
||||
HTMLVideoElement.prototype.canPlayType = canPlayType;
|
||||
canPlayType = null;
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
// by default, patch the video element
|
||||
vjs.Html5.patchCanPlayType();
|
||||
})();
|
||||
|
||||
// List of all HTML5 events (various uses).
|
||||
vjs.Html5.Events = 'loadstart,suspend,abort,error,emptied,stalled,loadedmetadata,loadeddata,canplay,canplaythrough,playing,waiting,seeking,seeked,ended,durationchange,timeupdate,progress,play,pause,ratechange,volumechange'.split(',');
|
||||
|
||||
@ -300,27 +349,3 @@ vjs.Html5.disposeMediaElement = function(el){
|
||||
})();
|
||||
}
|
||||
};
|
||||
|
||||
// HTML5 Feature detection and Device Fixes --------------------------------- //
|
||||
|
||||
// Android 4.0 and above can play HLS to some extent but it reports being unable to do so
|
||||
if (vjs.ANDROID_VERSION >= 4.0) {
|
||||
(function() {
|
||||
var canPlayType = HTMLVideoElement.prototype.canPlayType,
|
||||
mpegurlRE = /^application\/(?:x-|vnd\.apple\.)mpegurl$/i;
|
||||
|
||||
HTMLVideoElement.prototype.canPlayType = function(type) {
|
||||
if (type && mpegurlRE.test(type)) {
|
||||
return "maybe";
|
||||
}
|
||||
return canPlayType.call(video.constructor.prototype, type);
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
// Override Android 2.2 and less canPlayType method which is broken
|
||||
if (vjs.IS_OLD_ANDROID) {
|
||||
document.createElement('video').constructor.prototype.canPlayType = function(type){
|
||||
return (type && type.toLowerCase().indexOf('video/mp4') != -1) ? 'maybe' : '';
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user