Skip to content

feat: adds iosCategory update functionality#2259

Closed
watadarkstar wants to merge 3 commits into
doublesymmetry:mainfrom
watadarkstar:update-ios-category
Closed

feat: adds iosCategory update functionality#2259
watadarkstar wants to merge 3 commits into
doublesymmetry:mainfrom
watadarkstar:update-ios-category

Conversation

@watadarkstar

@watadarkstar watadarkstar commented Feb 28, 2024

Copy link
Copy Markdown

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)

Comment thread ios/RNTrackPlayer/RNTrackPlayer.swift Outdated

updateCategory(config: options)

configureAudioSession()

Copy link
Copy Markdown
Author

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)

Copy link
Copy Markdown

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.

@watadarkstar

watadarkstar commented Feb 28, 2024

Copy link
Copy Markdown
Author

@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

dcvz commented Feb 28, 2024

Copy link
Copy Markdown
Contributor

@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

watadarkstar commented Feb 28, 2024

Copy link
Copy Markdown
Author

@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

Copy link
Copy Markdown
Contributor

Possibly related to #2285

@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions Bot added the Stale label Jul 29, 2024
@github-actions

github-actions Bot commented Aug 5, 2024

Copy link
Copy Markdown
Contributor

This PR was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions Bot closed this Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants