doublesymmetry / react-native-track-player

A fully fledged audio module created for music apps. Provides audio playback, external media controls, background mode and more!
https://rntp.dev/
Apache License 2.0
3.18k stars 981 forks source link

feat: adds iosCategory update functionality #2259

Open watadarkstar opened 4 months ago

watadarkstar commented 4 months ago

Why

It allows you to switch modes at run time. For example, if you have an app that plays both audio and video you may need to update the iosCategoryMode at runtime

For some reason we found that to get CarPlay to broadcast the audio from track player using audio it needs IOSCategoryMode.SpokenAudio and for video it needs IOSCategoryMode.VideoRecording.

How

I moved some of the logic into an updateCategory function so it can be reused and the iosCategoryMode can be updated as well as other ios properties (see docs I've updated)

watadarkstar commented 4 months ago

@dcvz @jspizziri

When I was testing this on my app for some reason switching the iosCategoryMode causes the track player controls to disappear. I'm hoping you can provide some guidance as to why that may be happening?

dcvz commented 4 months ago

@dcvz @jspizziri

When I was testing this on my app for some reason switching the iosCategoryMode causes the track player controls to disappear. I'm hoping you can provide some guidance as to why that may be happening?

Are you perhaps calling update with an empty capabilities array? Docs say that we update new capabilities, but I think we've found that not all of them do, and omitting them is like setting them as empty.

watadarkstar commented 4 months ago

@dcvz Hey David thanks for the reply, I'm not calling update with an empty capabilities array. See my code below. You will notice the additional iosCategory property I added as well. Any other ideas as to why the track player controls may be disappearing, after I added iosCategory this started to happen.

await TrackPlayer.updateOptions({
        android: {
          appKilledPlaybackBehavior:
            AppKilledPlaybackBehavior.StopPlaybackAndRemoveNotification,
        },
        // stoppingAppPausesPlayback is deprecated but we still use it just in
        // case it's needed.
        // stoppingAppPausesPlayback: true,
        capabilities: [
          Capability.Play,
          Capability.Stop,
          Capability.Pause,
          Capability.JumpBackward,
          Capability.JumpForward,
          Capability.SeekTo,
        ],
        compactCapabilities: [
          Capability.Play,
          Capability.Pause,
          Capability.JumpForward,
          Capability.JumpBackward,
          Capability.SeekTo,
          Capability.Stop,
        ],
        progressUpdateEventInterval: 1,
        // We patched this so this works
        // eslint-disable-next-line @typescript-eslint/ban-ts-comment
        // @ts-ignore
        iosCategoryMode,
      })

@dcvz @jspizziri When I was testing this on my app for some reason switching the iosCategoryMode causes the track player controls to disappear. I'm hoping you can provide some guidance as to why that may be happening?

Are you perhaps calling update with an empty capabilities array? Docs say that we update new capabilities, but I think we've found that not all of them do, and omitting them is like setting them as empty.

jspizziri commented 2 months ago

Possibly related to https://github.com/doublesymmetry/react-native-track-player/pull/2285