Airplay audio only with Safari

437 views Asked by At

I'm trying to use the Safari's Airplay API to play an audio file to an Airplay device:

<audio id="player" src="audio.mp3" controls style="width: 100%"></audio>
<button id="airplay" disabled>airplay</button>

<script>
    const player = document.getElementById('player');
    const airplay = document.getElementById('airplay');

    player.addEventListener('webkitplaybacktargetavailabilitychanged', e => {
        airplay.disabled = e.availability !== 'available';
    });

    airplay.addEventListener('click', () => player.webkitShowPlaybackTargetPicker());
</script>

The button is working as expected but the device is unable to play. I'm trying on an AppleTV and when I try to use it the screen flashes and nothing happen (no music, the player is paused).

I have tried with an AAC file and the behavior is the same.

Any suggestions?

0

There are 0 answers