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

AudioService.start stucks after route popped on swipe back / back button press #418

Closed
Aqluse opened this issue Aug 11, 2020 · 16 comments
Closed
Assignees
Labels
1 backlog bug Something isn't working

Comments

@Aqluse
Copy link

Aqluse commented Aug 11, 2020

Which API doesn't behave as documented, and how does it misbehave?
At least starting from 0.11.2, up to newest 0.13.0

Minimal reproduction project
https://github.com/Aqluse/audio_service

To Reproduce (i.e. user steps, not code)
Steps to reproduce the behavior:

  1. Tap 'Go to a second page' button
  2. Swipe back or use back button to return to a first page (initial) by popping route.
  3. Tap 'Start audio service'
  4. Observe it stuck at awaiting answer from AudioService.start

Flutter SDK version
v1.17.5

Additional context
As I discovered right before filing this issue, AudioServiceWidget has overriden didPopRoute which is exactly what getting called when back button pressed / swipe back occured. It seems like AudioService is disconnected within, which seems to cause subject of this issue.

@Aqluse Aqluse added 1 backlog bug Something isn't working labels Aug 11, 2020
@ryanheise
Copy link
Owner

Thanks for reporting this bug. However before I can look at it, please follow the instructions as follows:

Minimal reproduction project
Provide a link here using one of two options:

  1. Fork this repository and modify the example to reproduce the bug, then provide a link here.
  2. If the unmodified official example already reproduces the bug, just write "The example".

It may not seem like much, however I have many issues to investigate and so I tend not to spend the time on an issue until it is ready for me to clone and test. Thanks.

@Aqluse
Copy link
Author

Aqluse commented Aug 12, 2020

@ryanheise done

@ryanheise
Copy link
Owner

Can you check that it compiles without error?

@Aqluse
Copy link
Author

Aqluse commented Aug 12, 2020

Fixed, must be now, I just checked for it

@ryanheise
Copy link
Owner

Thanks @Aqluse I was able to run it and confirmed what is happening.

Looking at your code, I noticed that you have not put the AudioServiceWidget in the right place. It must placed at the root of your home widget (see the README for an example). You should let MaterialApp (and hence WidgetsApp) do its top level initialisation first, and this allows it to correctly manage back button presses.

@Aqluse
Copy link
Author

Aqluse commented Aug 12, 2020

@ryanheise I will look how it act in that place, I use initialRoute now though

@ryanheise
Copy link
Owner

Your initial route still has a root widget inside, so that is where you can insert AudioServiceWidget.

@Aqluse
Copy link
Author

Aqluse commented Aug 12, 2020

Well, it works that way, thanks. Sorry for bothering, maybe it'll be worth to write a sentence about it in more insisting way?

@ryanheise
Copy link
Owner

That's a good idea, thanks for the suggestion. I've just clarified the README and docs.

@Maadhav
Copy link

Maadhav commented Dec 24, 2020

I have my AudioServiceWidget wrapped to the MyApp() widget.
runApp(AudioServiceWidget(child: new MyApp()));

After which I have used WillPopScope due to having to use the navigator widget. Now when I swipe to go back (Android Back), my onWillPop gets invoked, but after that, the UI gets disconnected from the background and all the stream listeners also get stopped being called i.e. AudioService.disconnect() gets called.

@ryanheise
Copy link
Owner

@Maadhav Did you mean to ask a question in particular? Or are you just attempting to summarise the preceding discussion? (I'm honestly not clear on that because there seems to be a disconnect between your comment and the comment immediately preceding it.)

@Maadhav
Copy link

Maadhav commented Dec 24, 2020

@ryanheise So, basically I am facing an issue with the implementation of audio_service in my flutter project. As mentioned above in my comment, I have wrapped the AudioServiceWidget to MyApp(), which is the root widget of my app. Now I have also used WillPopScope inside my widget tree. So the issue is that when I swipe to go back the onWillPop() callback is invoked, but the audioservice also gets disconnected and as a result, my UI stops updating.
Now I read the code of the plugin and saw that you have implemented

@override
Future<bool> didPopRoute() async {
AudioService.disconnect();
}

Now, why does didPopRoute get called when I swipe back inside my widget tree.
Also, what's the whole purpose of disconnecting the audio service when Navigtor.pop() is called?
Please let me know if you understood my issue or not.

@ryanheise
Copy link
Owner

Since your question is actually identical to the one asked in the first post, I will copy and paste my previous answer:

Looking at your code, I noticed that you have not put the AudioServiceWidget in the right place. It must placed at the root of your home widget (see the README for an example). You should let MaterialApp (and hence WidgetsApp) do its top level initialisation first, and this allows it to correctly manage back button presses.

I am not sure if you have done it, but please read the original question and notice that your code makes the same mistake, therefore my existing answer above equally applies to you. I hope that the new README makes it clear, but if not, can you tell me what is unclear so that I can improve it?

@Maadhav
Copy link

Maadhav commented Dec 24, 2020

OK got it.

@ryanheise
Copy link
Owner

👍

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs, or use StackOverflow if you need help with audio_service.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1 backlog bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants