The canPlayType
property for audio and video in JS is so bad that the official valid responses are "probably" and "maybe". There are many cases where we might want to know if an audio|video tag is gonna blow up in our face before even attempting to make a MediaElementPlayer
instance out of it.
The best (and most cautious) way to tackle this is to whitelist types by browser. Imagine that one implemented MEjs in TinyMCE's rich editor mode, this would be very helpful. Add `isCompatible( $media )` to `wp.media.mixin`. Future features will use this. See #27389. git-svn-id: https://develop.svn.wordpress.org/trunk@27539 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
2ba763c9ba
commit
bfd0ac1099
@ -307,6 +307,71 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
isCompatible: function ( media ) {
|
||||||
|
if ( ! media.find( 'source' ).length ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var ua = window.navigator.userAgent.toLowerCase(),
|
||||||
|
ff, chrome, opera, safari,
|
||||||
|
isIE = ua.match(/MSIE/gi) !== null,
|
||||||
|
isOpera = window.navigator.userAgent.match(/OPR/) !== null,
|
||||||
|
isOldIE = ua.match(/MSIE [6-8]/gi) !== null,
|
||||||
|
isChrome = ua.match(/safari/gi) && ua.match(/chrome/gi) !== null,
|
||||||
|
isFirefox = ua.match(/firefox/gi) !== null,
|
||||||
|
isSafari = ua.match(/safari/gi) !== null && ua.match(/chrome/gi) === null;
|
||||||
|
|
||||||
|
if ( isOldIE || isIE ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( isOpera ) {
|
||||||
|
opera = false;
|
||||||
|
media.find( 'source' ).each(function (i, elem) {
|
||||||
|
if ( elem.type.match(/video\/(ogv|webm)/gi) !== null ||
|
||||||
|
( elem.type.match(/audio\/(ogg|wav)/gi) !== null ) ) {
|
||||||
|
opera = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return opera;
|
||||||
|
} else if ( isChrome ) {
|
||||||
|
chrome = false;
|
||||||
|
media.find( 'source' ).each(function (i, elem) {
|
||||||
|
if ( elem.type.match(/video\/(mp4|m4v|mpeg|webm|ogg)/gi) !== null ||
|
||||||
|
elem.type.match(/audio\/(ogg|mpeg|x-ms-wma)/gi) !== null ) {
|
||||||
|
chrome = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return chrome;
|
||||||
|
|
||||||
|
} else if ( isFirefox ) {
|
||||||
|
ff = false;
|
||||||
|
media.find( 'source' ).each(function (i, elem) {
|
||||||
|
if ( elem.type.match(/video\/(ogg|webm)/gi) !== null ||
|
||||||
|
( elem.type.match(/audio\/(ogg|mpeg)/gi) !== null && -1 === elem.src.indexOf('.m4a') ) ) {
|
||||||
|
ff = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return ff;
|
||||||
|
|
||||||
|
} else if ( isSafari ) {
|
||||||
|
safari = false;
|
||||||
|
media.find( 'source' ).each(function (i, elem) {
|
||||||
|
if ( elem.type.match(/video\/(mp4|m4v|mpeg|x-ms-wmv|quicktime)/gi) !== null ||
|
||||||
|
( elem.type.match(/audio\/(mpeg|wav)/gi) !== null ) ) {
|
||||||
|
safari = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return safari;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override the MediaElement method for removing a player.
|
* Override the MediaElement method for removing a player.
|
||||||
* MediaElement tries to pull the audio/video tag out of
|
* MediaElement tries to pull the audio/video tag out of
|
||||||
|
Loading…
Reference in New Issue
Block a user