Eric
Eric

Reputation: 672

Audio background mode not working with react-native-track-player

I'm currently use react-native-track-player version 1.1.8 to stream audio from Internet. It works fine (react-native version 0.61.4)

I would like now to use it in background mode, to be able to continue to listen to radio if my app is in background mode.

I followed instructions from https://react-native-kit.github.io/react-native-track-player/background/, so add capabilities in xCode, which should be enough.

It doesn't work so I also add

TrackPlayer.updateOptions({
    stopWithApp: false
});

but stil not working on real device on iOS 13. I can see this message when the app goes background :

Can't end BackgroundTask: no background task exists with identifier 1 (0x1),
or it may have already been ended. 
Break in UIApplicationEndBackgroundTaskError() to debug.

But breakpoint does not give additional informations.

Any idea or experience with this audio library in background mode? Thanks!

Upvotes: 4

Views: 4875

Answers (3)

Justin.Mathew
Justin.Mathew

Reputation: 481

For me, ticking, in Xcode, Audio, Airplay, and Picture in Picture was the thing that did the trick. I didn't need to tick Background Processing

enter image description here

Upvotes: 1

1.Ticking Background processing as well in Background modes:

Background modes

2.Adding Permitted background task scheduler identifiers to my app target at Xcode (info tab) with my app identifier as value.

<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
</array>

Upvotes: 2

guy
guy

Reputation: 352

It seems that the background permissions structure in iOS 13 changed.

I had the same issue and solved it by:

  1. Ticking Background processing as well in Background modes: enter image description here
  2. Adding Permitted background task scheduler identifiers to my app target at Xcode (info tab) with my app identifier as value.

Upvotes: 4

Related Questions