Skip to content

Restart the Audio playback #2430

Open
Open
@AnandSharmaoo7

Description

Describe the Bug
After any other app starts playing it stops the audio but when other app stops playing it isn't starting the playback automatically

Steps To Reproduce
by using these settings
export async function setupPlayer() { const setup = async () => { try { await TrackPlayer.setupPlayer({ autoHandleInterruptions: true, iosCategoryMode: IOSCategoryMode.SpokenAudio, iosCategory: IOSCategory.Playback, }); } catch (error) { return error.code; } }; while ((await setup()) === 'android_cannot_setup_player_in_background') { // A timeout will mostly only execute when the app is in the foreground, // and even if we were in the background still, it will reject the promise // and we'll try again: await new Promise(resolve => setTimeout(resolve, 1)); } await TrackPlayer.updateOptions({ capabilities: [Capability.Play, Capability.Pause], compactCapabilities: [Capability.Play, Capability.Pause], android: { appKilledPlaybackBehavior: AppKilledPlaybackBehavior.ContinuePlayback, alwaysPauseOnInterruption: true, }, progressUpdateEventInterval: 2, }); await TrackPlayer.setRepeatMode(RepeatMode.Queue); }

Code To Reproduce
Services.js
`import TrackPlayer, {Event} from 'react-native-track-player';

module.exports = async function () {
TrackPlayer.addEventListener(Event.RemotePlay, async () => {
await TrackPlayer.play();
});

TrackPlayer.addEventListener(Event.RemotePause, async () => {
await TrackPlayer.pause();
});

TrackPlayer.addEventListener(Event.RemoteDuck, async event => {
if (event.paused) {
await TrackPlayer.pause();
} else {
await TrackPlayer.play();
}
});
};
`

Replicable on Example App?
didn't tried

Environment Info:
Paste the results of npx react-native info
System:
OS: macOS 15.2
CPU: (10) arm64 Apple M4
Memory: 717.70 MB / 16.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 23.5.0
path: /opt/homebrew/bin/node
Yarn:
version: 1.22.22
path: /opt/homebrew/bin/yarn
npm:
version: 10.9.2
path: /opt/homebrew/bin/npm
Watchman:
version: 2024.12.02.00
path: /opt/homebrew/bin/watchman
Managers:
CocoaPods:
version: 1.16.2
path: /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 24.2
- iOS 18.2
- macOS 15.2
- tvOS 18.2
- visionOS 2.2
- watchOS 11.2
Android SDK: Not Found
IDEs:
Android Studio: 2024.2 AI-242.23339.11.2421.12700392
Xcode:
version: 16.2/16C5032a
path: /usr/bin/xcodebuild
Languages:
Java:
version: 17.0.13
path: /usr/bin/javac
Ruby:
version: 3.4.1
path: /opt/homebrew/opt/ruby/bin/ruby
npmPackages:
"@react-native-community/cli": Not Found
react:
installed: 18.2.0
wanted: 18.2.0
react-native:
installed: 0.73.0
wanted: 0.73.0
react-native-macos: Not Found
npmGlobalPackages:
"react-native": Not Found
Android:
hermesEnabled: true
newArchEnabled: false
iOS:
hermesEnabled: Not found
newArchEnabled: false
Paste the exact react-native-track-player version you are using
"react-native-track-player": "4.0.1"
Real device? Or simulator?
Real Device
What OS are you running?
adroid 10.0

How I can Help
i may be forgetting something to add in the setup environment please check and revert
What can you do to help resolve this?
I can provide more info if you like also open to any suggestions
Have you investigated the underlying JS or Swift/Android code causing this bug?
Not sure where to look.
Can you create a Pull Request with a fix?
Yes
Thank you so much for this library.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions