mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
68e83901f3
PR-URL: https://github.com/nodejs/node/pull/46912 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
56 lines
1.2 KiB
JavaScript
56 lines
1.2 KiB
JavaScript
/**
|
|
* Returns the URL of a supported video source based on the user agent
|
|
* @param {string} base - media URL without file extension
|
|
* @returns {string}
|
|
*/
|
|
function getVideoURI(base)
|
|
{
|
|
var extension = '.mp4';
|
|
|
|
var videotag = document.createElement("video");
|
|
|
|
if ( videotag.canPlayType &&
|
|
videotag.canPlayType('video/ogg; codecs="theora, vorbis"') )
|
|
{
|
|
extension = '.ogv';
|
|
}
|
|
|
|
return base + extension;
|
|
}
|
|
|
|
/**
|
|
* Returns the URL of a supported audio source based on the user agent
|
|
* @param {string} base - media URL without file extension
|
|
* @returns {string}
|
|
*/
|
|
function getAudioURI(base)
|
|
{
|
|
var extension = '.mp3';
|
|
|
|
var audiotag = document.createElement("audio");
|
|
|
|
if ( audiotag.canPlayType &&
|
|
audiotag.canPlayType('audio/ogg') )
|
|
{
|
|
extension = '.oga';
|
|
}
|
|
|
|
return base + extension;
|
|
}
|
|
|
|
/**
|
|
* Returns the MIME type for a media URL based on the file extension.
|
|
* @param {string} url
|
|
* @returns {string}
|
|
*/
|
|
function getMediaContentType(url) {
|
|
var extension = new URL(url, location).pathname.split(".").pop();
|
|
var map = {
|
|
"mp4": "video/mp4",
|
|
"ogv": "application/ogg",
|
|
"mp3": "audio/mp3",
|
|
"oga": "application/ogg",
|
|
};
|
|
return map[extension];
|
|
}
|