[英]BigVideo.js - Check if supported by browser, background image fallback
I'm using BigVideo.js ( http://dfcb.github.io/BigVideo.js/ ) and want to be able to check if it is supported by the browser, if not, then show a background image instead. 我正在使用BigVideo.js( http://dfcb.github.io/BigVideo.js/ ),希望能够检查浏览器是否支持它,如果不支持,则显示背景图像。
Here's what I have: 这是我所拥有的:
var BV = new $.BigVideo({ //set container for video
container: $('#intro')
});
BV.init(); //initialise
if (Modernizr.touch) { //show background image for touch devices
BV.show('img/intro-bg.jpg');
} else {
BV.show('vids/bubble.mp4', { //set video format - x-browser support
ambient: true
});
BV.show('vids/bubble.webm', {
ambient: true
});
BV.show('vids/bubble.ogv', {
ambient: true
});
BV.show([{
type: "video/mp4", //make it loop
src: "vids/bubble.mp4"
}, {
type: "video/webm",
src: "vids/bubble.webm"
}, {
type: "video/ogg",
src: "vids/bubble.ogv"
}, {
ambient: true
}
]);
}
This works great in all modern browsers, but failed in an old version of Opera. 这在所有现代浏览器中都很好用,但是在旧版本的Opera中失败了。 When this happens we see an error message instead of the video:
发生这种情况时,我们会看到错误消息而不是视频:
The video could not be loaded, either because the server or network failed or because the format is not supported.
由于服务器或网络故障或不支持该格式,因此无法加载视频。
Rather than show this I would prefer to fallback to a background image. 我宁愿回退到背景图片,也不想显示此内容。 I've tried the following with no luck:
我已经尝试了以下方法,但是没有运气:
if( !BV ){
//show fallabck
}
and 和
if( !BV.init() ){
//show fallback
}
Anyone else figured out a way to do this? 还有其他人想出办法吗?
Try this: (stick in in your else block after the Modernizr.touch test) 尝试以下操作:(在Modernizr.touch测试之后,粘贴在您的else块中)
BV.getPlayer().ready(function(){
this.on('canplaythrough', function(){
// show fallback, eg:
$('#big-video-wrap').addClass('canplaythrough');
});
});
Adding the class canplaythrough
would work if I had in my CSS & HTML: 如果我的CSS和HTML中包含类,
canplaythrough
可以添加canplaythrough
类:
<div class="background">
<div id="big-video-wrap"><!-- this is auto-injected--></div>
</div>
<style>
#big-video-wrap { visibility:hidden; }
#big-video-wrap.canplaythrough { visibility:visible; }
.background { background:url(/** whatever your img is **/); }
</style>
This basically works because you can use the on
method to hook onto standard w3c video events . 这基本上是可行的,因为您可以使用
on
方法挂接到标准的w3c视频事件 。 I believe these work for flash too but I need to confirm this still . 我相信这些也可以用于Flash, 但是我仍然需要确认这一点 。
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.