html5 video fallback advice (no flash)

孤者浪人 提交于 2020-01-05 03:44:24

问题


I'm looking for a creative way to replace an HTML5 video with an image under a few circumstances. Don't want to deal with flash or anything like that to make the video work... would rather give them an image.

Give them the image if:

  1. If the desktop browser doesn't support HTML5 video

  2. If the user is mobile

Seems simple... especially by using Modernizr for css tags with display:none; if the video isn't supported ... so here's the caveat: The HTML5 video is edge to edge and centered to the screen with JavaScript and I'd like the image to have the same behavior.

My initial thought was simple: poster attribute. Works on an iPad and iPhone 3/3gs, but is playable on an iPhone 4.. Also, doesn't work on IE, which apparently says "I don't know what this is" and doesn't even bother with the poster.

I've got a test set up at http://kzmnt.com/test/

Looking forward to your advice!


回答1:


You can check if HTML5 video is supported with the following:

function supports_h264_baseline_video() {
 if (!supports_video()) { return false; }
 var v = document.createElement("video");
 return v.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"');
}

As far as mobile goes, try using some media queries.

The above code is from http://diveintohtml5.ep.io/detect.html#video-formats.




回答2:


Used a media query after about 1100px and replaced it with an image using css background size set to cover!



来源:https://stackoverflow.com/questions/6576746/html5-video-fallback-advice-no-flash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!