大网数据广告活动
Web 标准与前端开发

InputDeviceInfo: getCapabilities() method

· 52CE 我爱测

The **`getCapabilities()`** method of the InputDeviceInfo interface returns a `MediaTrackCapabilities` object describing the primary audio or video track of the device's MediaStream.

Media Capture and Streams

The getCapabilities() method of the InputDeviceInfo interface returns a MediaTrackCapabilities object describing the primary audio or video track of the device's MediaStream.

Syntax

getCapabilities()

Parameters

None.

Return value

A MediaTrackCapabilities object which specifies the value or range of values which are supported for each of the user agent's supported constrainable properties. It is required to return identical information as returned by calling getCapabilities() on the first MediaStreamTrack of the same kind as this device (video or audio) in the MediaStream returned by getUserMedia({ deviceId: deviceInfo.deviceId }).

See MediaStreamTrack.getCapabilities() for a list of commonly supported properties and their types.

[!NOTE] If the user has not granted permission to access the input device an empty object will be returned.

Examples

In the following example we ask for permission to access audio and video devices with mediaDevices.getUserMedia(), as to use getCapabilities() we need permission to access the devices.

If device is an InputDeviceInfo object, then getCapabilities() will return an object with members representing its capabilities. A video stream will not include auto properties such as noiseSuppression, for example.

// Get permission to access audio or video devices
navigator.mediaDevices
  .getUserMedia({ audio: true, video: true })
  // Enumerate media devices
  .then(() => navigator.mediaDevices.enumerateDevices())
  .then((devices) => {
    devices.forEach((device) => {
      if (typeof device.getCapabilities === "function") {
        console.log("Capabilities:", device.getCapabilities()); // A MediaTrackCapabilities object.
      } else {
        console.log("Device does not support getCapabilities:", device);
      }
    });
  })
  .catch((mediaError) => {
    console.error("Error accessing media devices:", mediaError);
  });

Specifications

Browser compatibility

See also

  • MediaStreamTrack.getCapabilities(), which also return a MediaTrackCapabilities object.

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。