Web Analytics Made Easy -
StatCounter Safari failing to load mp3 file. - CodingForum


No announcement yet.

Safari failing to load mp3 file.

  • Filter
  • Time
  • Show
Clear All
new posts

  • Safari failing to load mp3 file.

    I have this code:
    let sampleChime = function(a)
        a: obect;{'selection':string; mp3 file}
        target = a.id;
        chime = new Audio();
        chime.src = 'chimes/'+a.selection;
        chime.addEventListener('error', audioHandler, false);
        chime.addEventListener("canplaythrough", e => { setLength(e, 'start');});
        chime.addEventListener("loadeddata", e => { chime.play();});
        chime.addEventListener("ended", e => { setLength(e, 'end')});
    It is being called in and onchange event handler for a select/opt element.
    The selection list is for a group of short mp3 files of chimes.

    The setLength function gets a time stamp at the start
    and a time stamp at the end and subtracts start time from end time
    to get the duration of the chime. This will be used in a timer cycle that
    has a beginning chime and an end chime.

    This works fine in Firefox and Chrome.

    In Safari this is the error I get:
    (Safari Version 13.1.2 (13609.
    Unhandled Promise Rejection: NotAllowedError: The request is not allowed by the user agent
    or the platform in the current context, possibly because the user denied permission.

    Does anyone here have any idea why Safari is choking on this?

    I have set up a demo at:

    Thank you for time and attention
    Last edited by anotherJEK; Jun 20, 2022, 01:39 PM.

  • #2
    I encountered the same problem years ago. It seems the browser will reject the pro-grammatical request for play. I had to wait for click event and inside that click, issue the play request. I guess the idea is to prevent the application from playing unwanted sound request.

    BTW I found this. https://stackoverflow.com/questions/...avascript-play


    • #3
      O.K..!.... josephm; your reply led me to the solution: the auto play preference was set to block all auto play. So I turned it
      to allow all and now the sampling through the select/opt change event handler works.