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. Built from https://develop.svn.wordpress.org/trunk@27539 git-svn-id: http://core.svn.wordpress.org/trunk@27382 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
117d1bd31e
commit
bd4085fac3
|
@ -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
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue