-
-
Notifications
You must be signed in to change notification settings - Fork 969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: adds iosCategory update functionality #2259
base: main
Are you sure you want to change the base?
feat: adds iosCategory update functionality #2259
Conversation
@@ -346,6 +349,10 @@ public class RNTrackPlayer: RCTEventEmitter, AudioSessionControllerDelegate { | |||
interval: ((options["progressUpdateEventInterval"] as? NSNumber) ?? 0).doubleValue | |||
) | |||
|
|||
updateCategory(config: options) | |||
|
|||
configureAudioSession() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dcvz Can I call this here safely? I realize that reinitialization is something that should be avoided based on this code inside setupPlayer
:
reject("player_already_initialized", "The player has already been initialized via setupPlayer.", nil)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can update this safely since the phone switches nicely between the two speakers when updating the iosCategory and iosCategoryMode properties.
When I was testing this on my app for some reason switching the |
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. |
@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 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,
})
|
Possibly related to #2285 |
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 runtimeFor 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 theiosCategoryMode
can be updated as well as other ios properties (see docs I've updated)