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 980 forks source link

feat: make it possible to play audio through the earpiece speaker #2285

Open Egbert-Jan opened 3 months ago

Egbert-Jan commented 3 months ago

This new functionality allows you to set the audioUsageType and audioContentType for Android, and the iosCategroy and iosCategoryMode for iOS with the updateOptions function. This makes it possible to force the audio to come through the earpiece speaker. This can for example be useful to play an audio message in a chat app. For this to work on Android I also made a pull request in KotlinAudio (https://github.com/doublesymmetry/KotlinAudio/pull/105). I tried but could not get the RNTP example app to use the updated KotlinAudio repo while executing the publishToMavenLocal steps as shown in https://github.com/doublesymmetry/react-native-track-player/tree/main/example.

Example: TrackPlayer.updateOptions({ iosCategory: IOSCategory.PlayAndRecord, iosCategoryMode: IOSCategoryMode.VoiceChat, androidAudioContentType: AndroidAudioContentType.Music, androidAudioUsageType: AndroidAudioUsageType.VoiceCommunication })

Egbert-Jan commented 2 months ago

Hello @jspizziri @dcvz, could you maybe take a look at this pull request? I think it would be a useful feature. If something is wrong with it I could fix it.

dcvz commented 2 months ago

Hey @Egbert-Jan we've been a bit busy, but I'll get to it as soon as I can.

Egbert-Jan commented 2 months ago

Thanks I resolved the documentation and import issues. Have you also noticed I made a pull request here: https://github.com/doublesymmetry/KotlinAudio/pull/105. Those changed are needed for these to work.

jspizziri commented 2 months ago

@watadarkstar & @Egbert-Jan , it seems that there is some overlap between your two PRs (https://github.com/doublesymmetry/react-native-track-player/pull/2259). Can the two of you evaluate and and if I'm not mistaken, collaborate?

Egbert-Jan commented 1 month ago

My pull request introduces the same functionality as #2259 for the iOS side. However it also adds the functionality to the Android side.

tfkennedy777 commented 1 month ago

Just chiming in to say that I really appreciate the contributions on this issue, and I'm rooting for this to get merged! Would be super helpful to update these options on the fly after initialization.