https://github.com/web-platform-tests/wpt
Raw File
Tip revision: 92ea85944695eb6db9a1c60b5982ea3335f180a4 authored by Philip Jägenstedt on 03 April 2018, 21:38:14 UTC
can't link to chrome://, give up
Tip revision: 92ea859
media.js
//
// Returns the URI of a supported video source based on the user agent
//
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 URI of a supported audio source based on the user agent
//
function getAudioURI(base)
{
    var extension = '.mp3';

    var audiotag = document.createElement("audio");

    if ( audiotag.canPlayType &&
         audiotag.canPlayType('audio/ogg') )
    {
        extension = '.oga';
    }

    return base + extension;
}

function getMediaContentType(url) {
    var extension = new URL(url, location).pathname.split(".").pop();
    var map = {
        "mp4": "video/mp4",
        "ogv": "video/ogg",
        "mp3": "audio/mp3",
        "oga": "audio/ogg",
    };
    return map[extension];
}
back to top