4

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!

AmerllicA
  • 29,059
  • 15
  • 130
  • 154
Eric
  • 592
  • 10
  • 26
  • What version of `react-native-track-player` are you using? I got background mode working with version `1.1.8` following the instructions you linked – Fernando SA Dec 03 '19 at 11:30
  • @Ballenato I updated the question with version number and additional informations – Eric Dec 05 '19 at 08:11
  • the message "can't end backgroundtask..." is a iOS 13 bug – Ilario Dec 07 '19 at 11:33
  • @Ilario Ok I saw that apparently it's an iOS bug. Anyway it's a warning and I don't think it's the cause of the problem but the consequence, my background audio is stopped for whatever reason, and then this message appears. – Eric Dec 07 '19 at 12:57

3 Answers3

4

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.
guy
  • 342
  • 2
  • 11
  • Thanks for the workaround. Anyway it does not work for me. When you say app identifier, can you confirm it's the same as $(PRODUCT_BUNDLE_IDENTIFIER) ? – Eric Dec 09 '19 at 13:30
  • 1
    Another thing : the problem appears only on the physical device, not on the simulator. – Eric Dec 09 '19 at 13:31
  • I can confirm that playing audio while the app is in background requires activating _Background processing_, so the [Track Player docs](https://react-native-track-player.js.org/background) should be updated. I don't see _Permitted background task scheduler identifiers_ anywhere in the _Info_ tab - but then, the _Custom iOS Target Properties_ table in current Xcode _Version 12.1 (12A7403)_ is completely useless, the columns can't be expanded, so its values are hardly visible. – ssc Nov 04 '20 at 11:26
2

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>
1

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

Justin.Mathew
  • 413
  • 5
  • 12