搜索知道检测特定音频视频格式文件支持的库 [英] In search for a library that knows to detect support for specific Audio Video format files
问题描述
我正在构建一个移动网络应用程序,我正在实施Video&音频标签。显然并非所有设备都知道运行所有文件格式。 Modernizr知道将Codec返回给我,但我怎么知道我的文件是否有这个特定的编解码器?
I`m building a mobile-web app, and I am implementing Video & Audio tags. Apparently not all devices know to run all file formats. Modernizr knows to return to me the Codec, but how can I know if my file has this specific codec?
我可以识别文件扩展名或mim-type,但是我需要将编解码器与文件扩展名进行比较,并使用这些数据维护一个数组,这看起来像是一个花哨的任务。
I can identify the file extension or mim-type, but than I`ll need to compare the codec with the file extension, and maintain an array with this data, and this seems like a sisyphic task.
你们怎么说?有谁知道一个知道的图书馆向我们提供这些信息?或者也许我的方法是错误的,这是一个更好的方法来实现这一点。
What do you guys say? Any one knows on a good library that knows provide us with this information? Or maybe my approach is wrong and theres a better way to achive that.
请注意,Firefox OS不会向用户显示特定文件格式的msg操作系统支持,但在处理音频文件时,他不提供此信息。这意味着我需要向用户提供此反馈,我也更愿意以自定义的方式对我的应用程序进行此操作。
Please not that Firefox OS for example display a msg to the user that specific file format isn't supported by the OS, but he doesn`t provide this msg when dealing with Audio files. Which means that I need to provide this feedback to the user, and I also prefer to do it in a customised visual way to my application.
示例:
我收到了video.mp4。 Modernizr返回H264的编解码器。这两条信息没有关系。
我无法为我的视频提供后备广告以适用于所有可用的视频格式。该应用程序是云文件托管的浏览器(如dropbox),如果用户上传了一个无法在FirefoxOS上运行的文件,他必须看到理解为什么它的文件不运行,为此我需要这个库,而不是我自己管理这种压缩。
An example: I got video.mp4. Modernizr returns Codec of H264. this two pieces of information don't relate. I cannot place fallbacks for my video to run in all video formats available. The app is a browser of a Cloud Files Hosting (like dropbox) and if the user uploaded a file which cannot run on FirefoxOS, than he must see understand why its file don`t run, and for that I need this library, instead of managing this compression by myself.
一些参考文献:
- Mozile - Supported media formats
- Dive Into HTML5 - detect video formats
谢谢。
推荐答案
如果你有权访问mime类型,你只需使用音频
或视频
的 canPlayType()
方法:
If you have access to the mime type you could simply use the audio
or video
's canPlayType()
method:
canPlay = (function(){
var a = document.createElement('audio'),
v = document.createElement('video');
function canPlayAudio(type){
var mime = 'audio/';
if (a && a.canPlayType) {
if (type.indexOf(mime) === -1) type = mime+type;
return !!a.canPlayType(type) || !!a.canPlayType(type.replace(/^audio\/(x-)?(.+)$/, mime+'x-$2'))
} return false
}
function canPlayVideo(type){
var mime = 'video/';
if (v && v.canPlayType) {
if (type.indexOf(mime) === -1) type = mime+type;
return !!v.canPlayType(type) || !!v.canPlayType(type.replace(/^video\/(x-)?(.+)$/, mime+'x-$2'))
} return false
}
return {
audio: canPlayAudio,
video: canPlayVideo
}
})();
然后你可以执行这样的测试(注意:包括音频/
或video /
部分是可选的):
Then you can perform the tests like this (note: including the "audio/"
or "video/"
part is optional):
canPlay.audio('audio/mpeg') // true
canPlay.audio('m4a') // true
canPlay.audio('wav') // true
canPlay.audio('flac') // false
canPlay.audio('audio/ogg') // true
canPlay.video('video/mpeg') // false
canPlay.video('video/mp4') // true
canPlay.video('m4v') // true
canPlay.video('video/webm') // true
canPlay.video('avi') // false
这篇关于搜索知道检测特定音频视频格式文件支持的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!