Skip to content

Audio keeps playing even if the app is in background. To kill the audio, one must close the app. #16

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

Closed
abhishekUpmanyu opened this issue Jul 19, 2018 · 2 comments

Comments

@abhishekUpmanyu
Copy link

No description provided.

@luanpotter
Copy link
Member

Hi, @abhishekUpmanyu , thanks for the feedback!

This is actually as expected, as that might be the desired behavior for the audioplayers plugin. Agreed it's not the most usual for a game, but the fix is easy enough! The Game class has a listener for changes in the app lifecycle, which can hook to resume and paused. You can also stop your update logic with a flag variable as well, so that your game doesn't update while on background.

Just implement it in your BaseGame, something like this:

  @override
  void lifecycleStateChange(AppLifecycleState state) {
    if (state != AppLifecycleState.resumed) {
      // pause your updates
      // pause all audio players
    } else {
      // resume your updates
      // resume all audio players
    }
  }

@abhishekUpmanyu
Copy link
Author

Thank you for replying. Sorry it took me 2 days to come back here, I wasn't able to access the PC for that time. Being new to app development I didn't know about AppLifecycleState. Thank you so much for the solution, and really sorry for bothering you with the issue, I am closing the issue now 😅

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