Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display fallback image even if the browser supports html5 video

This might sound strange, but can I still display fallback image in that case?

Since video elements in mobile (Android & iOS) will open its native video player app when clicked, I want to show GIF version of the video (which I will place as the fallback image) for Android & iOS. I know how to detect whether the browser is mobile or not via Javascript, I just need some advice on best practice.

What I'm doing

<video>
    <source mp4>
    <source ogg>
    <source webm>
    <img src="*.gif">
</video>

Then in the js

if(site.isMobile()){
    $('video').hide();
    $('video img').show();
}

Of course it doesn't work since the img is inside video. I figure I can clone the img and append it before the video element and then hide the video element, something like this :

if(site.isMobile()){
    $('video img').clone().prependTo('video'); // just some pseudocode
    $('video').hide();
}

Is it a good practice though? Is there any simpler solution?

like image 552
Henson Avatar asked Mar 19 '13 12:03

Henson


People also ask

What is fallback video?

Video fallback, also known as waterfall or client-side mediation, maximizes the likelihood of filling an impression opportunity when you're using VAST redirects. With fallback, Ad Manager determines the eligibility of ads, ranks them accordingly, and returns a slate of ads, rather than just one.

How do I add a fallback image?

We can use the onerror attribute on the image to set a fallback. We use the onerror to set the error to null and set the src of the image to a fallback. In our case, a photo of a missing cat. Note: It's not a great practice to rely on external images.

What is the correct HTML element for displaying video files?

<video>: The Video Embed element. The <video> HTML element embeds a media player which supports video playback into the document. You can use <video> for audio content as well, but the <audio> element may provide a more appropriate user experience.


1 Answers

poster may be what you're looking for:

Poster: A URL indicating a poster frame to show until the user plays or seeks. If this attribute isn't specified, nothing is displayed until the first frame is available; then the first frame is displayed as the poster frame. -Via https://developer.mozilla.org/en-US/docs/HTML/Element/video

Example:

<video width="316" height="161" poster="https://i.stack.imgur.com/BfXRi.png" controls>
  <source src="https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" type="video/mp4" />
  <source src="https://clips.vorwaerts-gmbh.de/big_buck_bunny.ogv" type="video/ogg" />
  Your browser does not support the video tag.
</video>
like image 64
couzzi Avatar answered Sep 20 '22 12:09

couzzi