HTML5 Video tag with fallback

2019-08-01 19:29发布

I'm looking for a solution for embedding video and audio in html. The new videotag supports .ogg and .mp4, but is there a fallback solution for .flv and other formats?
For example, if I want to embed an .ogg, it will check whether or not html5 is supported, if not, it uses the fallback. If I want to embed a .flv is uses the fallback.

1条回答
Bombasti
2楼-- · 2019-08-01 19:53

html5 tag supports a fallback to any element, if the browser cannot interpret the video tag. here s a quick example for a fallback to a flash-file.

<video controls width="500">  
  <!-- if Firefox -->  
  <source src="video.ogg" type="video/ogg" />  
  <!-- if Safari/Chrome-->  
  <source src="video.mp4" type="video/mp4" />  

  <!-- If the browser doesn't understand the <video> element, then reference a Flash file. -->  
  <embed src="your_flash_file" type="application/x-shockwave-flash" width="1024" height="798" allowscriptaccess="always" allowfullscreen="true"></embed>  
</video>  

instead of the embed tag, you can take any html-element (f.e. a span with text "your browser cannot interpret html5.." or a picture or anything you want). basically, html5 browser take the videosource they can play, while non-html5 browser ignore the video and source tag and take the falback element at the end.

查看更多
登录 后发表回答