Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if video is playable on browsers by Javascript

I have a video tag in my video-sharing website

<video src="/video-123"></video>

The video is uploaded by users, which can be MP4, MOV,... and can be played on some browser, while others cannot (based on video encoding, for example H.264 is widely supported, but H.265 or HEVC only supported on newer Safari).
In the case the browser cannot play the video, I want to detect by Javascript on that browser, in order to show an error message to users. How can I do that? Please help me.

like image 963
code đờ Avatar asked Nov 19 '25 12:11

code đờ


1 Answers

Just insert any HTML tag inside <video> tag. Browsers which are supporting video format just will replace it.

<video src="/video-123">
  <div>Your browser does not support HTML5 video.</div>
</video>

or:

<video>
  <source src="/video-123.mp4" type="video/mp4">
  <source src="/video-123.ogg" type="video/ogg">
  
  <div>Your browser does not support HTML5 video.</div>
  
</video>
like image 103
dragomirik Avatar answered Nov 21 '25 02:11

dragomirik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!