Does anyone know how can I display an image for the browsers which don't support the tag ? Displaying a text such as in:
<video src="video.mp4" type="video/mp4">
Your browser does not support the <video> tag
</video>
Is easy, but if I replace the text with an img tag, it will always show the image, even when the browser DOES support the video tag.
Thanks for sharing your knowledge
(EDIT) This is not the case, my tests were wrong and img tag indeed gets rendered only when video is not supported (e.g. Safari 5)
There are 3 things to check: make sure your video files are properly encoded for web delivery. make sure the server where the videos are hosted is properly configured for web delivery. make sure your others scripts on the page do not interfere with video playback.
The <video> element is supported by all modern browsers. However, not all browsers support the same video file format. MP4 files are the most widely accepted format, and other formats like WebM and Ogg are supported in Chrome, Firefox, and Opera.
". wmv" video files are not supported by any browser.
I was just checking this link, as well as HTML5's spec, so this code should work for you:
<video controls="controls" poster="<your image poster if applicable>">
<source src="video.mp4" type="video/mp4" />
<img src="<your No video support image>" title="Your browser does not support the <video> tag" />
</video>
Using javascript, you can run:
var html5video = !!document.createElement('video').canPlayType;
That will be true or false depending on whether you have support or not. You can then use javascript to replace the video tag with an image, or, easier, just set the video to display:none;
and the image to display:block;
or vice versa.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With