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

Multiple players getting mixed up #403

Closed
cifkao opened this issue Feb 17, 2020 · 2 comments · Fixed by #418
Closed

Multiple players getting mixed up #403

cifkao opened this issue Feb 17, 2020 · 2 comments · Fixed by #418

Comments

@cifkao
Copy link
Contributor

cifkao commented Feb 17, 2020

Multiple players on one page don't seem to play well with each other. For example, in the callback_player demo, try clicking "play twinkle with click" first and while it is playing, click "play teapot without click". The following happens:

  • When the first player stops, the other one stops as well. However, only the callback for the first player gets called.
  • If you click "play twinkle with click" again, both sequences will play simultaneously in the same way as the first time (unless you click the stop button for the other sequence first).

Is it possible to implement players in such a way that they can play simultaneously? Otherwise I think possible solutions are:

  • Whenever a player wants to start playing, it should first stop any other player (and call its stop callback).
  • Prevent the player from starting if another player is playing.
  • Advise users to not use more than one player at a time.
@notwaldorf
Copy link
Collaborator

When the first player stops, the other one stops as well. However, only the callback for the first player gets called.
Yeah, this definitely looks like it's the case: code. When we call stop(), this also stops the tone.js Transport, which is going to also stop the other player.

I think the best solution for now is to document this (your option 3). Options 1 and 2 sound hard, because I don't know if we can tell from playerA that playerB also exists, so this sounds like a thing that should be checked on the app side, not the Player side. I really don't want to add a "PlayerManager" that keeps track of all the Players instantiated in the app and tries to manage them, so I think documenting this to cause less surprises is the best.

Would you like to send me a PR? 🙏

@cifkao
Copy link
Contributor Author

cifkao commented Feb 21, 2020

Looking at the code, couldn't option 2 be implemented just by checking Tone.Transport.state, and throwing an exception if it's already playing? And analogously for stopping, pausing and resuming. That seems like a more reasonable behavior (if you click the wrong button, nothing is going to happen, as opposed to unexpected things happening). It would also fix the demo, I think.

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

Successfully merging a pull request may close this issue.

2 participants