diff options
Diffstat (limited to '')
-rw-r--r-- | test/wpt/tests/common/media.js | 61 | ||||
-rw-r--r-- | test/wpt/tests/common/media.js.headers | 1 |
2 files changed, 62 insertions, 0 deletions
diff --git a/test/wpt/tests/common/media.js b/test/wpt/tests/common/media.js new file mode 100644 index 0000000..800593f --- /dev/null +++ b/test/wpt/tests/common/media.js @@ -0,0 +1,61 @@ +/** + * 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 ) + { + if (videotag.canPlayType('video/webm; codecs="vp9, opus"') ) + { + extension = '.webm'; + } else if ( 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", + "webm": "video/webm", + "mp3" : "audio/mp3", + "oga" : "application/ogg", + }; + return map[extension]; +} diff --git a/test/wpt/tests/common/media.js.headers b/test/wpt/tests/common/media.js.headers new file mode 100644 index 0000000..6805c32 --- /dev/null +++ b/test/wpt/tests/common/media.js.headers @@ -0,0 +1 @@ +Content-Type: text/javascript; charset=utf-8 |