While there are quite a few tracks, I wrote the following code in an attempt to implement something like selecting and playing a track in the select box, changing the audio tag to the next track when playback ends, playing again, and so on. However, when I run it locally, it works (looks like), but when I run it after uploading it to the server, the track is skipped, so when I look at the console, an error is thrown.

The variable form contains a select box
Variable a contains  tag
The variable num contains the current track number (obtained from the select box) numerically
The variable tracks contains a track list in an array format
a.addEventListener ("ended", function () {
  num = num + 1;
  form.selectedIndex = num;
  a.currentTime = 0;
  a.src = tracks [num];
  a.play ();
}, false);

VM5 script.js: 17 Uncaught (in promise) DOMException: The play () request was interrupted by a new load request.

There was a reference to google developers so I read it and tried various things but it didn't work ...

How can I solve it?

  • Answer # 1

    srcAfter changing the attribute valueloadeddataAfter waiting for the event to comeplay ()It may be necessary to do it.


  • Answer # 2

    When I run it locally, it works (looks like), but when I run it after uploading it to the server, the track is skipped.

    a.srcIf you change, it will be read from the server (browser cache), but the delay at this time will be taken into consideration.
    (In the state where reading is not completedplay ()Will result in an error).

    How can I solve it?

    By making full use of the event of the element, we will focus on the feature that "the player cannot make sound when exchanging (during) the sound source".

    Nowadays, compressed sound sources that are filed are common, but it is a hint to check old audio equipment as well.
    Replacing the source (sound source) involves exchanging the physical medium (tape medium/optical disk medium).

    Even now, the compressed sound source can be exchanged from the disk of the local machine.At high speedWill be done over the network (in server/network state)Always accompanied by delayYou need to think about the subtle differences.

    Source control features (such as "jukebox" and "CD changer",Sound source medium management/exchange functionProgrammatically realized)

    Player function (setOne medium(Play/stop/fast forward/rewind, etc. are realized by the program)