RemotePlayback: cancelWatchAvailability() 方法

可用性有限

此特性不是基線特性,因為它在一些最廣泛使用的瀏覽器中不起作用。

RemotePlayback 介面的 cancelWatchAvailability() 方法取消了監視一個或所有可用裝置的請求。

語法

js
cancelWatchAvailability()
cancelWatchAvailability(id)

引數

id 可選

特定遠端播放裝置的 callbackId

如果傳入特定裝置的 callbackId,則該裝置將從受監視裝置列表中移除。否則,整個列表將被清除。

返回值

一個 Promise,解析為 undefined

異常

InvalidStateError DOMException

如果媒體元素的 disableRemotePlaybacktrue,則丟擲此異常。

NotFoundError DOMException

如果傳入了 id 但它不匹配任何可用的 callbackId,則丟擲此異常。

示例

一旦識別並連線了遠端播放裝置,可以使用 cancelWatchAvailability() 停止監視可用裝置。

js
function switchToRemoteUI() {
  // Indicate that the state is 'connecting' or 'connected' to the user.
  // For example, hide the video element as only controls are needed.
  videoElem.style.display = "none";

  // Stop monitoring the availability of remote playback devices.
  videoElem.remote.cancelWatchAvailability();
}

規範

規範
Remote Playback API
# dom-remoteplayback-cancelwatchavailability

瀏覽器相容性