Search code examples
safarihtml5-audioamp-html

Safari plays audio only once when using <amp-audio>


I'm trying to have a short sound that I can play over multiple times by simply the play button on AMP. On Safari (desktop and mobile) the sound will only play once.

The sound is supposed to be triggered when the user clicks a button.

I've followed the amp documentation for the amp-audio and the audio events

<amp-audio preload="none" id="audio" controlslist="nodownload" hidden>
<div fallback><p>Your browser doesn't support HTML5 audio</p></div>
    <source type="audio/mpeg" src="/media/shortSound.mp3">
    <source type="audio/ogg" src="/media/shortSound.ogg">
</amp-audio>

The "native" audio button is hidden and is triggered by clicking the following button (with the on:tap event)

<div class="button" on="tap: audio.play" role="button" tabindex="0"></div>

I have also tried using absolute URLs in vain and using the pause function before play but to no avail.

Note: Unfortunately there is no .load event to circumvent the problem like with HTML5 on Safari (which is how I got to play it on Safari on the non-amp version)

Actual result: The sounds play once (the first time I click it). The rest of the time nothing happens, no message in the console either. What am I doing wrong?


Solution

  • I have found the issue was with the mp3 encoding of my files. It uses VBR instead of CBR, the problem doesn't happen when using CBR encoded mp3 files. To check your encoding I recommend using https://checkmate.gissen.nl/download.php

    EDIT: IT was actually because Safari uses HTTPRange to get its resources instead of a classic get method.