src/components/video/zy.media.js
function detectType(media, options, src) {
	var mediaFiles = [];
	var i;
	var n;
	var isCanPlay;

	// Get URL and type
	if (options.type) {
		// Accept either string or array of types
		if (typeof options.type == 'string') {
			mediaFiles.push({
				type: options.type,
				url: src
			});
		} else {
			for (i = 0; i < options.type.length; i++) {
				mediaFiles.push({
					type: options.type[i],
					url: src
				});
			}
		}
	} else if (src !== null) {
		// If src attribute
		mediaFiles.push({
			type: getType(src, media.getAttribute('type')),
			url: src
		});
	} else {
		// If <source> elements
		for (i = 0; i < media.children.length; i++) {
			n = media.children[i];

			if (n.nodeType == 1 && n.tagName.toLowerCase() == 'source') {
				src = n.getAttribute('src');
				mediaFiles.push({
					type: getType(src, n.getAttribute('type')),
					url: src
				});
			}
		}
	}

	// For Android which doesn't implement the canPlayType function (always returns '')
	if (zyMedia.features.isBustedAndroid) {
		media.canPlayType = function(type) {
			return /video\/(mp4|m4v)/i.test(type) ? 'maybe' : ''
		};
	}
	// For Chromium to specify natively supported video codecs (i.e. WebM and Theora) 
	if (zyMedia.features.isChromium) {
		media.canPlayType = function(type) {
			return /video\/(webm|ogv|ogg)/i.test(type) ? 'maybe' : ''
		};
	}

	if (zyMedia.features.supportsCanPlayType) {
		for (i = 0; i < mediaFiles.length; i++) {
			// Normal detect
			if (mediaFiles[i].type == "video/m3u8" || media.canPlayType(mediaFiles[i].type).replace(/no/, '') !== ''
				// For Mac/Safari 5.0.3 which answers '' to canPlayType('audio/mp3') but 'maybe' to canPlayType('audio/mpeg')
				|| media.canPlayType(mediaFiles[i].type.replace(/mp3/, 'mpeg')).replace(/no/, '') !== ''
				// For m4a supported by detecting mp4 support
				|| media.canPlayType(mediaFiles[i].type.replace(/m4a/, 'mp4')).replace(/no/, '') !== '') {
				isCanPlay = true;
				break
			}
		}
	}

	return isCanPlay
}
function detectType(media, options, src) {
	var mediaFiles = [];
	var i;
	var n;
	var isCanPlay;

	// Get URL and type
	if (options.type) {
		// Accept either string or array of types
		if (typeof options.type == 'string') {
			mediaFiles.push({
				type: options.type,
				url: src
			});
		} else {
			for (i = 0; i < options.type.length; i++) {
				mediaFiles.push({
					type: options.type[i],
					url: src
				});
			}
		}
	} else if (src !== null) {
		// If src attribute
		mediaFiles.push({
			type: getType(src, media.getAttribute('type')),
			url: src
		});
	} else {
		// If <source> elements
		for (i = 0; i < media.children.length; i++) {
			n = media.children[i];

			if (n.nodeType == 1 && n.tagName.toLowerCase() == 'source') {
				src = n.getAttribute('src');
				mediaFiles.push({
					type: getType(src, n.getAttribute('type')),
					url: src
				});
			}
		}
	}

	// For Android which doesn't implement the canPlayType function (always returns '')
	if (zyMedia.features.isBustedAndroid) {
		media.canPlayType = function(type) {
			return /video\/(mp4|m4v)/i.test(type) ? 'maybe' : ''
		};
	}
	// For Chromium to specify natively supported video codecs (i.e. WebM and Theora) 
	if (zyMedia.features.isChromium) {
		media.canPlayType = function(type) {
			return /video\/(webm|ogv|ogg)/i.test(type) ? 'maybe' : ''
		};
	}

	if (zyMedia.features.supportsCanPlayType) {
		for (i = 0; i < mediaFiles.length; i++) {
			// Normal detect
			if (mediaFiles[i].type == "video/m3u8" || media.canPlayType(mediaFiles[i].type).replace(/no/, '') !== ''
				// For Mac/Safari 5.0.3 which answers '' to canPlayType('audio/mp3') but 'maybe' to canPlayType('audio/mpeg')
				|| media.canPlayType(mediaFiles[i].type.replace(/mp3/, 'mpeg')).replace(/no/, '') !== ''
				// For m4a supported by detecting mp4 support
				|| media.canPlayType(mediaFiles[i].type.replace(/m4a/, 'mp4')).replace(/no/, '') !== '') {
				isCanPlay = true;
				break
			}
		}
	}

	return isCanPlay
}
function detectType ( media , options , src ) { var mediaFiles = [ ] ; var i ; var n ; var isCanPlay ; // Get URL and type if ( options . type ) { // Accept either string or array of types if ( typeof options . type == 'string' ) { mediaFiles . push ( { type : options . type , url : src } ) ; } else { for ( i = 0 ; i < options . type . length ; i ++ ) { mediaFiles . push ( { type : options . type [ i ] , url : src } ) ; } } } else if ( src !== null ) { // If src attribute mediaFiles . push ( { type : getType ( src , media . getAttribute ( 'type' ) ) , url : src } ) ; } else { // If <source> elements for ( i = 0 ; i < media . children . length ; i ++ ) { n = media . children [ i ] ; if ( n . nodeType == 1 && n . tagName . toLowerCase ( ) == 'source' ) { src = n . getAttribute ( 'src' ) ; mediaFiles . push ( { type : getType ( src , n . getAttribute ( 'type' ) ) , url : src } ) ; } } } // For Android which doesn't implement the canPlayType function (always returns '') if ( zyMedia . features . isBustedAndroid ) { media . canPlayType = function ( type ) { return / video\/(mp4|m4v) / i . test ( type ) ? 'maybe' : '' } ; } // For Chromium to specify natively supported video codecs (i.e. WebM and Theora)  if ( zyMedia . features . isChromium ) { media . canPlayType = function ( type ) { return / video\/(webm|ogv|ogg) / i . test ( type ) ? 'maybe' : '' } ; } if ( zyMedia . features . supportsCanPlayType ) { for ( i = 0 ; i < mediaFiles . length ; i ++ ) { // Normal detect if ( mediaFiles [ i ] . type == "video/m3u8" || media . canPlayType ( mediaFiles [ i ] . type ) . replace ( / no / , '' ) !== '' // For Mac/Safari 5.0.3 which answers '' to canPlayType('audio/mp3') but 'maybe' to canPlayType('audio/mpeg') || media . canPlayType ( mediaFiles [ i ] . type . replace ( / mp3 / , 'mpeg' ) ) . replace ( / no / , '' ) !== '' // For m4a supported by detecting mp4 support || media . canPlayType ( mediaFiles [ i ] . type . replace ( / m4a / , 'mp4' ) ) . replace ( / no / , '' ) !== '' ) { isCanPlay = true ; break } } } return isCanPlay }
Detect if current type is supported
Detect if current type is supported