简体   繁体   English

Chrome 错误检测是否可以播放 HLS 视频媒体

[英]Chrome is wrongly detecting can it play HLS video media

I am trying to programatically find out whether some media will play or not based on it's URL.我试图以编程方式找出某些媒体是否会根据其 URL 播放。

Based on browser testing, HLS will play fine on my Chrome browser using the videoJs player video library, however CanIUse is saying it won't which is my first confusion.根据浏览器测试,HLS 可以使用 videoJs 播放器视频库在我的 Chrome 浏览器上正常播放,但是 CanIUse 说它不会,这是我的第一个困惑。

在此处输入图片说明

I am then running it through this JavaScript...然后我通过这个 JavaScript 运行它......

using this npm package to get the mime-types使用这个 npm 包来获取 mime-types

https://www.npmjs.com/package/mime-types https://www.npmjs.com/package/mime-types

var mime = require('mime-types');

// get the extension of the file
var mimeType = mime.contentType(file.split('.').pop());

// returns 'application/vnd.apple.mpegurl'

var video = document.createElement('video');
console.log(Boolean(video.canPlayType(mimeType)));

Which returns false also, however it does play which is making me confused at how this is happening, does anyone have any ideas on why this is happening, or how I could correctly detect if the video will play or not?这也返回 false,但是它确实播放,这让我对这是如何发生的感到困惑,有没有人知道为什么会发生这种情况,或者我如何正确检测视频是否会播放?

The "Can I Use HLS" page lists the compatibility matrix for the HTML5 video tag, meaning that it checks if the browser has native support for that format. “我可以使用 HLS”页面列出了 HTML5 video标签的兼容性矩阵,这意味着它会检查浏览器是否支持该格式。 For example most desktop browsers except Safari on MacOS cannot play HLS natively.例如,除了 MacOS 上的 Safari 之外,大多数桌面浏览器都无法原生播放 HLS。

That's why for formats like Apple HLS and MPEG-DASH you need a JavaScript player which will transmux (repackage the streams without re-encoding) that specific format into one that the video element can process natively.这就是为什么对于像 Apple HLS 和 MPEG-DASH 这样的格式,您需要一个 JavaScript 播放器,它将转换(重新打包流而不重新编码)该特定格式转换为video元素可以本地处理的格式。

Regarding codecs you might either go for the lowest common denominator like H.264 baseline with AAC, or provide different formats tailored to the targeted device with a fallback mechanism.关于编解码器,您可以选择最低公分母,如带有 AAC 的 H.264 基线,或者提供针对具有回退机制的目标设备量身定制的不同格式。

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

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