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

RemotePlayback: prompt() method

· 52CE 我爱测

The **`prompt()`** method of the RemotePlayback interface prompts the user to select an available remote playback device and give permission for the current media to be played using that device.

Remote Playback API

The prompt() method of the RemotePlayback interface prompts the user to select an available remote playback device and give permission for the current media to be played using that device.

If the user gives permission, the RemotePlayback.state will be set to connecting and the user agent will connect to the device to initiate playback.

If the user chooses to instead disconnect from the device, the RemotePlayback.state will be set to disconnected and user agent will disconnect from this device.

Syntax

prompt()

Parameters

None.

Return value

A Promise that resolves with undefined after the user accepts or rejects the prompt.

Exceptions

The promise will be rejected with one of the following exceptions:

  • InvalidStateError DOMException
    • : Thrown if HTMLMediaElement.disableRemotePlayback is true for the media element.
  • OperationError DOMException
    • : Thrown if there is already an unsettled promise from a previous call to prompt() for this media element, or browsing context.
  • InvalidAccessError DOMException
    • : Thrown if the user has not interacted with this device recently.
  • NotSupportedError DOMException
    • : Thrown if the user agent knows that remote playback of this particular media is not feasible.
  • NotFoundError DOMException
    • : Thrown if remote playback is unavailable.
  • NotAllowedError DOMException
    • : Thrown if the user denies permission to use the device.

Security

Transient user activation is required. The user has to interact with the page or a UI element in order for this feature to work.

Examples

In the following example the user is prompted to select a remote playback device to play a video.

devicesBtn.onclick = () => {
  // Request the user to select a remote playback device.
  videoElem.remote
    .prompt()
    // Update the UI and monitor the connected state.
    .then(updateRemotePlaybackState);
  // Otherwise, the user canceled the selection UI or no screens were found.
};

Specifications

Browser compatibility

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

资料来源与适用范围

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

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

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