How to check if the browser can play mp4 via html5 video tag?
How to check if the browser can play mp4 via html5 video tag?
I made a function to validate if your browser is able to play audio or video element
const checkMedia = mediaType => {
let canPlay = false
const mediaFormat = {
audio: 'audio/mp3',
video: 'video/mp4'
}
let media = document.createElement(mediaType)
if (
media.canPlayType &&
media.canPlayType(mediaFormat[mediaType]).replace(/no/, '')
) {
canPlay = true
}
return canPlay
}