LLM
AirPlay¶
AirPlay lets viewers wirelessly stream HLS from Apple devices to compatible receivers such as Apple TVs, smart TVs, and Macs. PRESTOplay for Web Apps supports AirPlay through a dedicated plugin.
Code samples
AirPlay: an AirPlay button, availability and casting status, and the native HLS player on Safari.
See AirPlayPlugin for the full API.
Using the AirPlay plugin¶
This section shows how to integrate AirPlay with a custom UI.
Import the PRESTOplay AirPlay plugin:
import "@castlabs/prestoplay/cl.airplay";
Add an AirPlay button to your page:
<button id="airplay" style="display: none;">AirPlay</button>
Show the button when AirPlay is available:
const button = document.getElementById("airplay");
player.on(clpp.events.AIRPLAY_STATUS_CHANGED, (event) => {
if (event.canCast) {
button.style.display = "block";
} else {
button.style.display = "none";
}
});
Open the AirPlay target picker when the button is clicked:
button.addEventListener('click', function () {
const plugin = player.getPlugin(clpp.airplay.AirPlayPlugin.Id);
plugin.showCastMenu();
});
Listen for these events to detect the start and end of an AirPlay session:
player.on(clpp.events.AIRPLAY_CASTING_STARTED, () => {
// AirPlay casting session started
});
player.on(clpp.events.AIRPLAY_CASTING_ENDED, () => {
// AirPlay casting session ended
});
Next topic: Safari
Previous topic: Cast playlist