React-native-track-player: Audio Playback not stopping even after app close

Created on 31 Dec 2017  Â·  17Comments  Â·  Source: react-native-kit/react-native-track-player

App plays song even if app closed from task manager on Android
set stopWithApp flag to true but no luck

any idea how to stop music or close the app completely when closed from task manager?

Android Bug

Most helpful comment

@naody You may give a try setting stopWithApp to true.

TrackPlayer.updateOptions({
    stopWithApp: true
});

All 17 comments

+1

I am also running into this issue – spent the night debugging it without result..

This SO question seems to point to onTaskRemoved no longer being called when the service is bound to using bindService(intent, mConnection, Context.BIND_AUTO_CREATE);

Now when starting the service with startService(intent) the onTaskRemoved() method gets called but it is never called when I bind to the service using bindService(intent, mConnection, Context.BIND_AUTO_CREATE);

It seems to be fixed for me by changing in TrackModule:

        // Binds the service to get a MediaWrapper instance
        Intent intent = new Intent(context, PlayerService.class);
        intent.setAction(PlayerService.ACTION_CONNECT);
        context.bindService(intent, this, Service.BIND_AUTO_CREATE);

to

        // Binds the service to get a MediaWrapper instance
        Intent intent = new Intent(context, PlayerService.class);
        context.startService(intent);
        intent.setAction(PlayerService.ACTION_CONNECT);
        context.bindService(intent, this, 0);

onTaskRemoved is being called again in PlayerService when I kill the app from the task manager.

With latest code as well getting same issue, on android force close application still audio playing.
Please suggest any solution, i am using "react-native-track-player": "^0.2.5" version.

@hsparihar-systango does it still happens on 1.0.0?

@Guichaguri
it's resolved now,
Thanks

@Guichaguri, music still continues playing in the background after closing the app.
Currently using version react-native-track-player: 1.0.0 on Android Pi, any tricks I need to know? :)

Thanks

@naody You may give a try setting stopWithApp to true.

TrackPlayer.updateOptions({
    stopWithApp: true
});

@moonstruck, yup I haven't missed that one :). Here's my setup

   await TrackPlayer.setupPlayer({
      maxCacheSize: 1024 * 5, // 5 mb
    });

    TrackPlayer.updateOptions({
      stopWithApp: true,
      capabilities: [
        TrackPlayer.CAPABILITY_PLAY,
        TrackPlayer.CAPABILITY_PAUSE,
        TrackPlayer.CAPABILITY_SEEK_TO,
        TrackPlayer.CAPABILITY_SKIP_TO_NEXT,
        TrackPlayer.CAPABILITY_SKIP_TO_PREVIOUS,
      ],
    });

@moonstruck, yup I haven't missed that one :). Here's my setup

   await TrackPlayer.setupPlayer({
      maxCacheSize: 1024 * 5, // 5 mb
    });

    TrackPlayer.updateOptions({
      stopWithApp: true,
      capabilities: [
        TrackPlayer.CAPABILITY_PLAY,
        TrackPlayer.CAPABILITY_PAUSE,
        TrackPlayer.CAPABILITY_SEEK_TO,
        TrackPlayer.CAPABILITY_SKIP_TO_NEXT,
        TrackPlayer.CAPABILITY_SKIP_TO_PREVIOUS,
      ],
    });

For now this trick worked form me.

  componentWillUnmount = async () => {
    AppState.removeEventListener('change', this._handleStateChange);
    await TrackPlayer.reset();
    await TrackPlayer.stop();
  };

TrackPlayer.updateOptions({ stopWithApp: true });

This solves the issue for me guys

This issue still on 1.2.3 version, on IOS.
TrackPlayer.updateOptions({ stopWithApp: true }); doesn't work

@ithustle, what are you expecting on iOS?

stopWithApp is an Android only settings.

Also, are you saying that even after force quitting the app on iOS, by swiping it out of multitasking view, the audio continues to play?

No, forcing quitting the app, stop playing.
But on previous versions (if my mind don't trick me) after restart app on fast refresh the song playing stopped

This could be implemented by your app, but it is not a feature of react-native-track-player. Resuming the app from the background on iOS should have no effect, unless you have implemented something to react to this scenario. If you still think there is a bug, please create a separate issue for iOS, as this issue is specifically for the Android stopWithApp setting.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

moduval picture moduval  Â·  4Comments

EhteshamAnwar picture EhteshamAnwar  Â·  3Comments

mnlbox picture mnlbox  Â·  4Comments

mckmarc picture mckmarc  Â·  4Comments

KalebPortillo picture KalebPortillo  Â·  4Comments