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

Last track is replayed when ended #1

Open
eloiqs opened this issue Nov 6, 2020 · 1 comment
Open

Last track is replayed when ended #1

eloiqs opened this issue Nov 6, 2020 · 1 comment

Comments

@eloiqs
Copy link

eloiqs commented Nov 6, 2020

Thanks for this library, I would have wrote it myself but you beat me to it! (not complaining 👍 )

private autoPlayNext() {
if (this.config && this.config.autoPlayNext) {
this.next()
this.play()
}
}

Right now when the last track ends, there are some safeguards in the next function that prevents the stream from nexting to an unexistant next track, but play still gets called. I wonder if this is intentional?

I have a one track stream and would like to just stop the stream when it ends. I tried implementing it myself:

    this.audioStream.events().subscribe((event) => {
      if (event.type === 'ended' && this.state.isLastTrack) {
        this.audioStream.stop();
      }
    });

But it looks like this runs before autoPlayNext gets called here

canPlay$.pipe(switchMap(event => ended$)).subscribe(value => this.autoPlayNext())

@eloiqs
Copy link
Author

eloiqs commented Nov 6, 2020

I just found a workaround for now, but is not the cleanest

    this.audioStream.events().subscribe((event) => {
      if (event.type === 'ended' && this.state.isLastTrack) {
        this.shouldHaveStopped = true;
      } else if (event.type === 'playing' && this.shouldHaveStopped) {
        this.audioStream.stop();
        this.shouldHaveStopped = false;
      }
    });

@imsingh imsingh pinned this issue Dec 5, 2020
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