开发者

When should HTML5 video fall back to Flash player?

开发者 https://www.devze.com 2023-01-07 20:09 出处:网络
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 d

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;
     }
   }


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

0

精彩评论

暂无评论...
验证码 换一张
取 消