0

I have got this error in my console in Chrome:

Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause().

Next to the error there is a link describing the error, the cause of the error and how to solve it, but I don't get it to work.

There are similar/related questions here at Stackoverflow, but none provides a solution (for jplayer).

I am using an old javascript libary jPlayer (version 2.9.2). It has not been updated for many years and the project is completely dead. I still am using it though (not really having another choice).

I tried to fix it using a promise, but that doesn't work. Example:

$jPlayer.jPlayer("setMedia", track);
    
var playPromise = $jPlayer.jPlayer("play");
    
if (playPromise !== undefined) {
  playPromise.then(_ => {
    // Automatic playback started!
    // Show playing UI.
  })
  .catch(error => {
    // Auto-play was prevented
    // Show paused UI.
  });
}

This results in "Uncaught TypeError: playPromise.then is not a function". $jPlayer.jPlayer("play") doesn't return a promise. So how to solve it?

When I look at one of the demo pages of jplayer "demo-02-jPlayerPlaylist.html" and I switch play lists, something similar happens. When I try to 'auto play' the list with

alert('play click');
$('.jp-play').click(); //auto play new list!

The first song should start playing, but it doesn't. If I turn these 2 lines around, the song starts to play and stops after 1 second. I am quite sure this is because of the "Autoplay policy in Chrome". No error here, but I think it is 100% related.

So do you know how to fix this? Note: I am not limited to the code of the JPlayer library. I can modify it to my liking.

Markus
  • 5,976
  • 5
  • 6
  • 21
RWC
  • 4,697
  • 2
  • 22
  • 29
  • Please add a minimal, reproducible code example that shows how we can get the error message "Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause()." with jplayer. Was this also because you tried to play a track without previous user interaction? – Markus Oct 24 '22 at 18:48
  • Isn't this example from the jplayer homepage exactly what you are looking for: https://www.jplayer.org/latest/quick-start-guide/example-audio-soundtrack/ ? – Markus Oct 24 '22 at 19:01
  • @Markus: I had a look at the example, but it doesn't make any difference. I provided an example which shows the same problem. It is not very easy to create a CodePen or Fiddle for this, but I will give it a try. There is user action (switching playlists) so that should give me enough to trigger the playing of the 1st song in the second list. – RWC Oct 24 '22 at 22:07
  • Please share a reproducible example of your code that shows what you want to do and that produces the error message "Uncaught (in promise) DOMException". – Markus Oct 28 '22 at 10:26

0 Answers0