I want react-native-trackplayer NOT to work in background mode. So when i close the app i want react-native-trackplayer to STOP.
I have already configured this for android
android: {
appKilledPlaybackBehavior: StopPlaybackAndRemoveNotification
},
I haven't tested it but the docs say it would work. I am now looking for a solution on IOS.
This is my code, i tried something with IOSBackgroundMode but i can't get it to work.
import TrackPlayer ,{ Capability, AppKilledPlaybackBehavior, StopPlaybackAndRemoveNotification, IOSCategory } from 'react-native-track-player';
import { PlaybackService } from './service';
registerRootComponent(App);
TrackPlayer.registerPlaybackService(() => PlaybackService);
TrackPlayer.setupPlayer({
iosCategoryMode: IOSCategory.Ambient
}).then(() => {
TrackPlayer.updateOptions({
android: {
appKilledPlaybackBehavior: StopPlaybackAndRemoveNotification
},
progressUpdateEventInterval: 2000,
color: "#ff35cf07",
// Media controls capabilities
capabilities: [
Capability.Play,
Capability.Pause,
Capability.SkipToNext,
Capability.SkipToPrevious,
Capability.Stop,
],
compactCapabilities: [
Capability.Play,
Capability.Pause,
Capability.SkipToNext,
Capability.SkipToPrevious,
Capability.Stop,
]
})
})
.catch(err => console.log('ERROR SETUP PLAYER', err));
This is what is in my service.js file (PlaybackService)
import TrackPlayer, {Event, IOSCategory} from 'react-native-track-player';
export const PlaybackService = async () => {
TrackPlayer.addEventListener(Event.PlaybackError, async (code, message) => {
});
TrackPlayer.addEventListener(Event.RemotePlay, async () => {
await TrackPlayer.play()
});
TrackPlayer.addEventListener(Event.RemotePause, async () => {
await TrackPlayer.pause()
});
TrackPlayer.addEventListener(Event.RemoteNext, async () => await TrackPlayer.skipToNext());
TrackPlayer.addEventListener(Event.RemotePrevious, async () => await TrackPlayer.skipToPrevious());
TrackPlayer.addEventListener(Event.RemoteSeek, (position) => TrackPlayer.seekTo(position));
}
react-native-trackplayer keeps playing in background, is there any solution for this?