HTML5视频何时应该回到Flash播放器? [英] When should HTML5 video fall back to Flash player?
问题描述
我正在为HTML5视频播放器实施回退机制。我有一个方法来取代它与swfobject Flash播放器,但我应该如何检测,如果有任何问题已经发展?
换句话说,如果我们使用以下可以抛出的错误事件列表,哪一个应该触发Flash播放器的替换?或者,如果发生错误,我们是否应该简单地进行更换?
另外,应该在哪里调用onError处理程序?我正在考虑视频标记,但是要确保。你的指导非常感谢。
函数失败(e){
//视频播放失败 - 显示消息说明为什么
switch(e.target.error.code){
case e.target.error.MEDIA_ERR_ABORTED:
alert('您放弃了视频播放。
break;
case e.target.error.MEDIA_ERR_NETWORK:
alert('网络错误导致视频下载失败。
break;
case e.target.error.MEDIA_ERR_DECODE:
alert('由于损坏问题或因为浏览器不支持的视频使用功能,视频播放被中止。
break;
case e.target.error.MEDIA_ERR_SRC_NOT_SUPPORTED:
alert('无法加载视频,因为服务器或网络发生故障或者格式不被支持。
break;
默认值:
alert('发生未知错误');
break;
$ / code $ / pre
解决方案这里的麻烦是许多问题不能通过切换到Flash来解决。实际上,只有当你真正从Flash中获益的时候,在IE,FF和Opera中,当你有MP4播放的时候,以及在所有的浏览器上都有FLV播放的时候。 (这显然可能会根据本地Flash对webm / Theora的支持而改变。)
为此,我们为JW Player for HTML5做了以下工作:
- 询问浏览器是否可以播放文件。
- 如果浏览器无法播放文件,检查基于文件的扩展名的Flash支持的文件类型列表
- 如果Flash无法播放该文件,请提供下载链接。
<这个解决方案并不是万无一失的,但它可以让你在那里获得90%以上的收益。
Best,
Zach
开发者,LongTail视频
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
这篇关于HTML5视频何时应该回到Flash播放器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!