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

Bug when App gets closed on Android #144

Closed
daniel-naegele opened this issue Apr 20, 2019 · 13 comments
Closed

Bug when App gets closed on Android #144

daniel-naegele opened this issue Apr 20, 2019 · 13 comments

Comments

@daniel-naegele
Copy link

Hi there,

there is a big bug in this plugin, even reproducible in the example.
When something is playing and you close the app via the back button on Android, the audio is still playing and in the console, this message gets spammed: D/FlutterNativeView( 5601): FlutterView.send called on a detached view, channel=xyz.luan/audioplayers`
When I open the app again, the audio still plays but on the dart side, there isn't anything playing. The dart side of the plugin is detached.

This is a critical bug. The iOS implementation seems to be good.

With kind regards,
Daniel

@erickzanardo
Copy link
Member

Hey, this errors message seems odd, we will take a look on it.

But be aware that handling application going to background, and back to foreground is not handled but the plugin, it must be handled but the application who uses it.

Thanks.

@daniel-naegele
Copy link
Author

Maybe it is a bug from flutter itself. Maybe it's worth to write a issue there @erickzanardo

@letiagoalves
Copy link

I am having the same problem. It only happens in Android. I am trying to use didChangeAppLifecycleState to stop the player but with no success.

@letiagoalves
Copy link

@Butzlabben have you found a solution?

@daniel-naegele
Copy link
Author

No @letiagoalves
@erickzanardo what about creating an issue in the flutter repository?

@letiagoalves
Copy link

has someone found a quick fix for this yet?

@daniel-naegele
Copy link
Author

I have found a workaround, I am now stopping the audio playback when the app gets closed this way.

You will need the back_button_interceptor dependency and your state widget needs to implement with RouteAware

  void initState() {
    super.initState();
    BackButtonInterceptor.add(myInterceptor);
  }

  @override
  void dispose() {
    BackButtonInterceptor.remove(myInterceptor);
    super.dispose();
  }

  bool myInterceptor(bool stopDefaultButtonEvent) {
    // Detect if app will close
    String currentRoute =
        BackButtonInterceptor.getCurrentNavigatorRouteName(context);
    bool canNotPop = currentRoute == "/";
    if (canNotPop) stopMyMusic();
    return false;
  }

@letiagoalves
Copy link

@Butzlabben and how do you handle the app being destroyed by sliding it from the OPEN APPS view?

@macbl
Copy link

macbl commented Jul 18, 2019

I'm suffering from the same Problem. When using the "back" button the app seems to be completely unloaded - even final static references are removed. When it is resumed, the audio player reference is a new one. (Pressing play will actually play two tracks simulaniously.)
It would be really helpful to be able to somehow restore a reference to a player instance that communicates to the same 'native channel'. I now players are supposed to have an id for native acces? Would that be an option?
I think as this plugins major purpose is to play audio a a service, this is should definitely be fixed. Stopping audio on app suspension is usually not what we want (althout Butzlabbens workaround is valuable for the moment).

@Wanchen7
Copy link

Any solutions? I'm try to use WidgetsBinding to pause/resume the player. When I pressed home button, it works fine, but no effect while back button pressed.
here is my code:

截屏2019-10-21下午5 48 00

@daniel-naegele
Copy link
Author

You will need the backbutton interceptor as shown in my workaround.

@Wanchen7
Copy link

You will need the backbutton interceptor as shown in my workaround.

3Q~ you save my time!

@erickzanardo
Copy link
Member

Like discussed on the issue, handling this is the responsibility of the app using the plugin, and not the plugin itself

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants