DisplayMediaStreamConstraints dictionary's audio property is used to specify whether or not to request that the MediaStream containing screen display contents also include an audio track. This value may simply be a Boolean, where true indicates that an audio track should be included an false (the default) indicates that no audio should be included in the stream.

More precise control over the audio data may be exercised by instead providing a MediaTrackConstraints object, which is used to process the audio prior to adding it to the stream.

注意: The specification for the Screen Capture API does not define what the contents of the audio track should be. This is left up to the 用户代理 to decide. Likely sources are the computer's system audio output and the user's microphone, but there is no way to specify which source to use.

句法

displayMediaStreamConstraints.audio = allowAudioFlag;
displayMediaStreamConstraints.audio = mediaTrackConstraints;
displayMediaStreamConstraints = {
  audio: allowAudioFlag|mediaTrackConstraints;
}
					

The value may be either a Boolean or a MediaTrackConstraints 对象。

If a Boolean is specified, a value of true indicates that an audio track should be included in the stream returned by getDisplayMedia() , if an appropriate audio source exists and the user agent supports audio on display media. A value of false —the default—indicates that no audio track is to be included in the stream.

MediaTrackConstraints object is given, and an audio source is available, an audio track matching the settings given in the constraints object is included in the MediaStream 返回通过 getDisplayMedia() .

If no audio source is available, or the user agent doesn't support audio tracks with getDisplayMedia() , the returned MediaStream has no audio track, but no error occurs. The audio track is always considered optional.

范例

规范

规范 状态 注释
未知
The definition of 'DisplayMediaStreamConstraints.audio' in that specification.
未知 初始定义

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.

No compatibility data found. Please contribute data for "api.DisplayMediaStreamConstraints.audio" (depth: 1) to the MDN 兼容性数据存储库 .

另请参阅

元数据

  • 最后修改: