Reputation: 5052
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.
Upvotes: 0
Views: 518