MediaRecorder:isTypeSupported() 静态属性
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2021.
MediaRecorder
接口的 isTypeSupported()
静态方法返回一个 Boolean
,如果指定的 MIME 媒体类型是用户代理应能成功录制的类型,则为 true
。
语法
js
MediaRecorder.isTypeSupported(mimeType)
参数
mimeType
-
需要检查的 MIME 媒体类型。
返回值
一个 Boolean
值,如果 MediaRecorder
实现能够录制指定 MIME 类型的 Blob
对象,则为 true
。如果没有足够的资源支持录制和编码过程,录制仍可能失败。如果值为 false
,则表示用户代理无法录制指定格式。
示例
js
const types = [
"video/webm",
"audio/webm",
"video/webm;codecs=vp8",
"video/webm;codecs=daala",
"video/webm;codecs=h264",
"audio/webm;codecs=opus",
"video/mp4",
];
for (const type of types) {
console.log(
`支持 ${type} 类型吗?${
MediaRecorder.isTypeSupported(type) ? "也许!" : "不能 :("
}`,
);
}
规范
Specification |
---|
MediaStream Recording # dom-mediarecorder-istypesupported |