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

MediaStreamTrack: contentHint property

· 52CE 我爱测

The **`contentHint`** property of the MediaStreamTrack interface is a string that hints at the type of content the track contains. Allowable values depend on the value of the MediaStreamTrack.kind property.

Media Capture and Streams

The contentHint property of the MediaStreamTrack interface is a string that hints at the type of content the track contains. Allowable values depend on the value of the MediaStreamTrack.kind property.

Value

A string with one of the following values:

  • ""
    • : No contentHint has been set.
  • "speech"
    • : The track should be treated as if it contains speech data. When setting this value, the value of MediaStreamTrack.kind must be "audio".
  • "speech-recognition"
    • : The track should be treated as if it contains data for the purpose of speech recognition by a machine. When setting this value, the value of MediaStreamTrack.kind must be "audio".
  • "music"
    • : The track should be treated as if it contains music. When setting this value, the value of MediaStreamTrack.kind must be "audio".
  • "motion"
    • : The track should be treated as if it contains video where motion is important. For example, webcam video, movies or video games. When setting this value, the value of MediaStreamTrack.kind must be "video".
  • "detail"
    • : The track should be treated as if video details are extra important. For example, presentations or web pages with text content, painting or line art. When setting this value, the value of MediaStreamTrack.kind must be "video".
  • "text"
    • : The track should be treated as if video details are extra important, and that significant sharp edges and areas of consistent color can occur frequently. For example, presentations or web pages with text content. When setting this value, the value of MediaStreamTrack.kind must be "video".

Examples

A function that sets the contentHint

This function takes a stream and a contentHint value, and applies the hint to each track. See the full example here, showing how different contentHint values change how the tracks display.

function setVideoTrackContentHints(stream, hint) {
  const tracks = stream.getVideoTracks();
  tracks.forEach((track) => {
    if ("contentHint" in track) {
      track.contentHint = hint;
      if (track.contentHint !== hint) {
        console.error(`Invalid video track contentHint: "${hint}"`);
      }
    } else {
      console.error("MediaStreamTrack contentHint attribute not supported");
    }
  });
}

Specifications

Browser compatibility

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

资料来源与适用范围

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

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

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