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

Attempt play sound with blocked audio context produce issues #103

Open
Burakovivan opened this issue Jan 20, 2021 · 0 comments
Open

Attempt play sound with blocked audio context produce issues #103

Burakovivan opened this issue Jan 20, 2021 · 0 comments

Comments

@Burakovivan
Copy link

Burakovivan commented Jan 20, 2021

Im working on some app that has calls, and im need to play incoming ringtone. Sometimes it happens that user open page and do not touch it at all (hence audiocontext are blocked), then at some point he got incoming call and no sound, its fine. User accept or decline call and im execute ion.sound.stop(ringtoneName). Still all fine at this point, as it was no sounds and im stop it - no sounds too. Also at this point audioContext are became to unblocked state and can be used without user 'gestures', in my case it will be used by event from webSocket. Next part are produce unexpected behaviour - when user receive one more call - it play sounds, all good, user accept or decline call, im execute stop() function BUT SOUND STILL PLAYS!

Have only one idea why it happens - first sound which was attempted to play with blocked context somehow 'captured' but not played, stop() does not drop it. So with second call to play() it start both sounds, and on second stop() it just stop one of them, and one of them stays. Not sure if i can prove this assumption, but it just looks like that.
It maybe obvious that i may fix issue with double call to stop() but its not, even if i will make second call with setTimeout, or if i will do 10 calls in loop, it still playing. BUT when im call stop() two times from console - it working fine.

Im using angular, maybe its important for this issue. for sounds im using this simple wrapper, and have another class that hold all sounds (variables type of SoundHandle). Im calling Play() and Stop() from events received by websocket

export class SoundHandle {
    constructor(private sound_name: string, private opts?: { part: string }) { }
    private get IonSound() { return window.ion.sound as IonSound };
    public Play() {
        this.IonSound.play(this.sound_name, this.opts); 
    }
    public Stop() {
        this.IonSound.stop(this.sound_name, this.opts);
        //setTimeout(() => {
        //    this.IonSound.stop(this.sound_name, this.opts);
        //}, 300); 

    }
}

I have live example, but its closed from public for the moment as it not in production yet. So if you will want to see what exactly happens on site - contact me and I will grant access to you, not in public conversation

Having problem with ion-sound v3.0.7, angular 9.1.0

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

1 participant