简体   繁体   English

如何检测浏览器是否支持MJPEG?

[英]How can I detect whether a browser supports MJPEG?

Modern browsers except IE handle MJPEG ( Motion JPEG ). 除IE之外的现代浏览器处理MJPEGMotion JPEG )。 Here is an example fiddle. 是一个小例子。

Can I detect support for MJPEG ? 我可以检测对MJPEG支持吗? I have looked through Modernizr in vain. 我看着Modernizr是徒劳的。

Modernizr only supports the following formats for detection right now: ogg, webm and h264. Modernizr目前仅支持以下格式进行检测:ogg,webm和h264。

The video element has a call called canPlayType(format) that would really be your only option (if it works for mjpg). 视频元素有一个叫做canPlayType(format)的调用,它真的是你唯一的选择(如果它适用于mjpg)。 Your detection logic would look something like this (not the format would be different). 您的检测逻辑看起来像这样(格式不同)。

var videoElement = document.createElement('video');
if(!!videoElement.canPlayType)
{
  var browserConfidence = videoElement.canPlayType('video/mjpeg; codecs="insert, them"');
  if(browserConfidence == "probably")
  {
    // high confidence
  }
  else if(browserConfidence == "maybe")
  {
    // low confidence
  }
  else
  {
    // no confidence... it definately will not play
  }
}

Make sure you visit the W3C's information on canPlayType . 请务必访问W3C关于canPlayType的信息 It looks like the mime type should be "video/mjpeg" and not "video/mjpg" as you specified earlier. 看起来mime类型应该是“video / mjpeg”而不是之前指定的“video / mjpg”。

I've tried the most obvious way to detect if the image could be loaded or not: 我尝试过最明显的方法来检测图像是否可以加载:

$output = $('<img id="webcam">')
        .attr('src', src)
        .load(function(){alert('ok')})
        .error(function(){alert('error')});

In case image could be loaded load event will be fired, otherwise error . 如果可以加载图像,则会触发load事件,否则会error Checked this in recent Chrome and IE8. 在最近的Chrome和IE8中检查了这一点。 Works as expected. 按预期工作。

Sadly for this you would need to use an ActiveX control to support mjpg in IE. 遗憾的是,你需要使用ActiveX控件来支持IE中的mjpg。 See How to embed mjpeg file on a webpage . 请参见如何在网页上嵌入mjpeg文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM