When should HTML5 video fall back to Flash player?

﹥>﹥吖頭↗ 提交于 2019-12-30 10:04:39

问题


I'm working on implementing a fallback mechanism for the HTML5 video player. I've got a way to replace it with the swfobject Flash player, but how should I detect if any issues have developed?

In other words, if we use the following list of error events that can be thrown, which one should trigger the Flash player replacement? Or should we simply do a replacement if any error is thrown?

Also, where should the onError handler be called? I'm thinking on the video tag, but want to make sure. Your guidance is much appreciated. Thanks.

   function failed(e) {
     // video playback failed - show a message saying why
     switch (e.target.error.code) {
       case e.target.error.MEDIA_ERR_ABORTED:
         alert('You aborted the video playback.');
         break;
       case e.target.error.MEDIA_ERR_NETWORK:
         alert('A network error caused the video download to fail part-way.');
         break;
       case e.target.error.MEDIA_ERR_DECODE:
         alert('The video playback was aborted due to a corruption problem or because the video used features your browser did not support.');
         break;
       case e.target.error.MEDIA_ERR_SRC_NOT_SUPPORTED:
         alert('The video could not be loaded, either because the server or network failed or because the format is not supported.');
         break;
       default:
         alert('An unknown error occurred.');
         break;
     }
   }

回答1:


The trouble here is that many issues can't be fixed by switching to Flash. In fact, the only time you're really benefited by switching to Flash is in IE, FF, and Opera when you've got an MP4 to play, and in all browsers when you've got an FLV. (This is obviously subject to change based on native Flash support for webm / Theora.)

For this reason, we've done the following for the JW Player for HTML5:

  • Ask the browser if it can play the file.
  • If the browser can't play the file, check the list of supported file types for Flash based on the file's extension.
  • If Flash can't play the file, offer a download link.

This solution isn't foolproof, but it gets you 90%+ of the way there.

Best,

Zach

Developer, LongTail Video



来源:https://stackoverflow.com/questions/3247338/when-should-html5-video-fall-back-to-flash-player

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