Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I display an image if browser does not support HTML5's <video> tag

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)

like image 560
mpaf Avatar asked Mar 15 '12 10:03

mpaf


People also ask

Why is my video tag in HTML not working?

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.

Does Chrome support the video tag?

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.

Which video format is not supported in HTML video tag?

". wmv" video files are not supported by any browser.


2 Answers

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>
like image 164
DarkAjax Avatar answered Sep 24 '22 02:09

DarkAjax


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.

like image 44
Rich Bradshaw Avatar answered Sep 26 '22 02:09

Rich Bradshaw