HTML5 video, fallback to flash if no .ogv file

跟風遠走 提交于 2019-12-08 00:36:59

问题


How can I fallback to a flash video player if the necessary file type is not present.

For example this code:

<video controls width="500">
    <source src="<?= $mov ?>" type="video/mp4" />
    <embed src="http://blip.tv/play/gcMVgcmBAgA%2Em4v" type="application/x-shockwave-flash" width="1024" height="798" allowscriptaccess="always" allowfullscreen="true"></embed>
</video>

Does not include an .ogv file, so in Firefox, an empty video player is displayed.

How can I fall back to a Flash player even if the html5 video tag is supported in the browswer?


回答1:


You can use JavaScript to detect it:

(function (video) {
    if (!video.canPlayType || !video.canPlayType('video/mp4')) {
        // Flash fallback
    }
}(document.createElement('video')));



回答2:


You should really include an .ogv file, that's not so much effort, there are so much video converter software, and you can also find online converters.


If you don't want to do that anyway

Use Modernizr.

What is Modernizr?

Modernizr adds classes to the <html> element which allow you to target specific browser functionality in your stylesheet. You don't actually need to write any Javascript to use it.

Have you ever wanted to do if-statements in your CSS for the availability of cool features like border-radius? Well, with Modernizr you can accomplish just that! The syntax is very intuitive, too:

.multiplebgs div p {
  /* properties for browsers that
     support multiple backgrounds */
}
.no-multiplebgs div p {
  /* optional fallback properties
     for browsers that don't */
}

Modernizr is a small and simple JavaScript library that helps you take advantage of emerging web technologies (CSS3, HTML 5) while still maintaining a fine level of control over older browsers that may not yet support these new technologies.

Modernizr uses feature detection to test the current browser against upcoming features like rgba(), border-radius, CSS Transitions and many more. These are currently being implemented across browsers and with Modernizr you can start using them right now, with an easy way to control the fallbacks for browsers that don’t yet support them.

Additionally, Modernizr creates a self-titled global JavaScript object which contains properties for each feature; if a browser supports it, the property will evaluate true and if not, it will be false.

Lastly, Modernizr also adds support for styling and printing HTML5 elements. This allows you to use more semantic, forward-looking elements such as <section>, <header> and <dialog> without having to worry about them not working in Internet Explorer.

What Modernizr doesn't do

Modernizr does not add missing functionality to browsers; instead, it detects native availability of features and offers you a way to maintain a fine level of control over your site regardless of a browser’s capabilities.

However if you're interested in that, you'll probably want to look here: HTML5 Cross browser Polyfills.




回答3:


just add another source tag

<source src="fileName.ogv" type="video/ogv" />

it will work....




回答4:


Here is a complete example of using video format fallbacks with a final fallback to Flash: http://diveintohtml5.info/video.html#example



来源:https://stackoverflow.com/questions/4763042/html5-video-fallback-to-flash-if-no-ogv-file

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