Riff / Built on the open web / Media

Remote Playback

Shows the cast button only when a Chromecast or AirPlay target is in reach.

Now Playing on a wide screen: the Song and Video switch at the top, the cover on the left, the Up next list on the right, and the player bar along the bottom
The cast control in the bar appears once a target is in reach.

How Riff uses it

The script watches availability once, and the callback shows or hides every cast button as a device comes in and out of range. Safari takes the equivalent WebKit path for AirPlay. Pressing the button prompts the browser's device picker on whichever element is live.

Why

There is no other standard way to know a device is near, so the buttons would either always show and do nothing, or never show.

Without it

Both calls are optionally chained, so a browser with neither keeps the buttons hidden.

Where

Links open the source at the commit this page was published from.

Reference: Remote Playback on MDN.