Skip to content

Conversation

alnitak
Copy link
Owner

@alnitak alnitak commented Sep 19, 2025

Description

As discussed in #312, calling stop immediately after calling play, produces the warning.

2 problems were causing the issue:

  1. the one discussed in the above issue: the play() doesn't have the time to produce a handle before the stop() is called.
  2. a stop() call after another event like scheduleStop or a sound ended that already stopped the handle, ie:
final handle = await SoLoud.instance.play(currentSound);
SoLoud.instance.scheduleStop(handle, const Duration(seconds: 3));
await delay(3500); // wait till the handle has already been stopped by scheduleStop
unawaited(SoLoud.instance.stop(handle));

This fixes both problems.

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • 🛠️ Bug fix (non-breaking change which fixes an issue)
  • ❌ Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactor
  • ✅ Build configuration change
  • 📝 Documentation
  • 🗑️ Chore

Copy link
Collaborator

@filiph filiph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Marco, thanks for the quick turnaround! I have a few questions below.

Comment on lines -773 to -774
if (player.get() == nullptr || !player.get()->isInited() ||
!player.get()->isValidHandle(handle))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, why are we no longer checking whether the handle is valid? Does Player::stop() not care?

Oh wait, we checked whether the handle was not valid? And then we stopped it? Sorry, I'm getting confused.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now the handle validity is managed by the voiceEndedCallbak. Whether or not it is valid, the callback is called and the SoLoud engine does nothing if the handle doesn't exist.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation!


void Player::stop(unsigned int handle)
{
removeHandle(handle);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] I guess I'd like to see it documented (in comments in this file, ideally) who is responsible for removing the handle (e.g. calling Player::removeHandle()).

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the handle here is now an error because it is now the voiceEndedCallck duty. I have written comments in that callback.

@alnitak
Copy link
Owner Author

alnitak commented Sep 22, 2025

Hey Filip, sorry for the late.

I agree, I'm stingy with comments. I have added some in the callback. If some more are needed, please let me know.

Copy link
Collaborator

@filiph filiph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for adding the additional comments!

Comment on lines -773 to -774
if (player.get() == nullptr || !player.get()->isInited() ||
!player.get()->isValidHandle(handle))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation!

@alnitak alnitak merged commit 845ec60 into main Sep 23, 2025
1 check passed
@alnitak alnitak deleted the stopFutures branch September 23, 2025 16:28
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 this pull request may close these issues.

2 participants