JS Get Media Mimetype From Url
Little function to grab the mime type from a video url, using it in one of my apps will continue to add to it.
function getMimeType(url) {
var ext = url.split(/[#?]/)[0].split('.').pop().trim();
switch (ext) {
case 'mp4':
return 'video/mp4'
break;
case 'mov':
return 'video/quicktime'
break;
case 'flv':
return 'video/x-flv'
break;
case 'm3u8':
return 'application/x-mpegURL'
break;
case 'ts':
return 'video/MP2T'
break;
case 'avi':
return 'video/x-msvideo'
break;
case 'wmv':
return 'video/x-ms-wmv'
break;
case 'webm':
return 'video/webm'
break;
case 'ogg':
return 'video/ogg'
break;
case 'm1v':
return 'video/mpeg'
break;
case 'mpd':
return 'application/dash+xml'
break;
default:
case 'application/octet-stream':
}
}
