files/en-us/web/api/remoteplayback/index.md
{{APIRef("Remote Playback API")}}
The RemotePlayback interface of the {{domxref('Remote Playback API','','',' ')}} allows the page to detect availability of remote playback devices, then connect to and control playing on these devices.
{{InheritanceDiagram}}
Also inherits properties from its parent interface, {{DOMxRef("EventTarget")}}.
RemotePlayback connection's state. One of:
"connecting"
"connected"
"disconnected"
Also inherits methods from its parent interface, {{DOMxRef("EventTarget")}}.
callbackId of an available remote playback device.Also inherits events from its parent interface, {{DOMxRef("EventTarget")}}.
The following example demonstrates a player with custom controls that support remote playback. Initially the button used to select a device is hidden:
<video id="videoElement" src="https://example.org/media.ext">
<button id="deviceBtn" class="hidden">Pick device</button>
</video>
.hidden {
display: none;
}
The {{domxref("RemotePlayback.watchAvailability()")}} method is used to watch for available remote playback devices. If a device is available, use the callback to show the button.
const deviceBtn = document.getElementById("deviceBtn");
const videoElem = document.getElementById("videoElement");
function availabilityCallback(available) {
// Show or hide the device picker button depending on device availability.
if (available) {
deviceBtn.classList.remove("hidden");
} else {
deviceBtn.classList.add("hidden");
}
}
videoElem.remote.watchAvailability(availabilityCallback).catch(() => {
// If the device cannot continuously watch available,
// show the button to allow the user to try to prompt for a connection.
deviceBtn.classList.remove("hidden");
});
{{Specifications}}
{{Compat}}