Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ugjka opened this issue Jul 25, 2017 · 3 comments

Comments

@ugjka
Copy link

ugjka commented Jul 25, 2017

Something is funky with Chrome on Android when I try to self-destruct (this.destruct()) on onfinish event. The thing crashes and my app won't play the next song.

soundmanager2.js:1307 sound4: load (http://music.ugjka.net/stream?id=4fa3cf33515636cee19b585d2863b8494beca314)
soundmanager2.js:1307 sound3: Destruct
soundmanager2.js:1307 sound3: unload()
soundmanager2.js:1307 HTML5::Ignoring timeupdate
soundmanager2.js:4195 Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause().
html5Unload @ soundmanager2.js:4195
SMSound.destruct @ soundmanager2.js:1846
onfinish @ common.js:104
(anonymous) @ soundmanager2.js:3364
wrapCallback @ soundmanager2.js:3651
SMSound._onfinish @ soundmanager2.js:3363
(anonymous) @ soundmanager2.js:3986
(anonymous) @ soundmanager2.js:3885
soundmanager2.js:1307 HTML5::Ignoring loadstart
soundmanager2.js:1307 HTML5::Ignoring error

this is the code

//Play song by id
function playSong(id){
    soundManager.stopAll();
    soundManager.createSound({
        id: ["sound", id].join(""),
        url: [music.url, "/stream?id=", music.playlist[id].ID].join(""),
        multiShot:false,
        onfinish: function() {
            if (music.current == (music.playlist.length - 1)) {
                music.current = 0;
            } else {
                music.current++;
            }
            playSong(music.current);
            $(["#sound", id].join("")).attr("playing", false);
            this.destruct();
        },
        onstop: function(){
            $(["#sound", id].join("")).attr("playing", false);
            this.destruct();
        },
        whileplaying: function(){
            if (music.sliderDrag == false){
                music.slider.value = (this.position / this.durationEstimate) * 1000;
            }
        },
    });
    $(["#sound", id].join("")).attr("playing", true);
    soundManager.play(["sound", id].join(""));
    document.getElementsByTagName("body")[0].style.backgroundImage = ["url(", music.url, "/art?id=", music.playlist[id].ID, ")"].join("");
}

This sometimes also happen on desktop Chrome, but very rarely

@ugjka
Copy link
Author

ugjka commented Jul 25, 2017

Ok, I solved this by simply reusing the sound object instead of creating a new one for each song

please feel free to close this if this feels like a design problem

@scottschiller
Copy link
Owner

scottschiller commented Aug 9, 2017

Hm! Apologies for the late follow up, and thanks for the report. When creating a new sound, SM2 should make a new Audio() object by default unless on a mobile device. Given you're on Android, it may be that destruct() destroys the single audio instance and then things might indeed go south. ;)

If you avoid using destruct(), you should be OK. If you want to be careful about saving resources, you can try calling the unload() method on the sound object before loading the next sound. This might be problematic on mobile because of their restrictions on "auto-play" - i.e., sound onfinish() -> unload() -> play() might get blocked, so it's worth testing on iOS and Android to see if the behaviour is OK.

I didn't expect destruct() to cause issues and hadn't considered the mobile / singleton audio object case there, so thanks for the heads-up.

@ugjka
Copy link
Author

ugjka commented Aug 10, 2017

Ok, unload() works on Android's Chrome, don't know about IOS though, don't have such a device

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants