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.3k stars 1.02k forks source link

audio not getting pause when app goes in background. Its playing continuously #2361

Open komalharmale56 opened 2 months ago

komalharmale56 commented 2 months ago

Describe the Bug when we play audio and while playing, I put app in background or you can say I minimize the App, it should stop playing the audio but it continuously playing

Steps To Reproduce Step 1: Play audio Step 2: while playing minimize the app/put in background step 3: audio still playing

Code To Reproduce const track1 = { id: ${id}, url: cloudURL, // Load media from the app bundle title: Channel ${channel}, artist: 'Monitor', };

await TrackPlayer.add([track1]); await TrackPlayer.updateOptions(options);

//////////////////////option.js file export const options = { android: { // This is the default behavior appKilledPlaybackBehavior: AppKilledPlaybackBehavior.PausePlayback, stopForegroundGracePeriod: 5, }, stopWithApp: true, // An array of media controls capabilities capabilities: [ Capability.Play, Capability.Pause, Capability.SkipToNext, Capability.SkipToPrevious, Capability.Stop, ],

// An array of capabilities that will show up when the notification is in the compact form compactCapabilities: [Capability.Play, Capability.Pause], };

Environment Info: ////////////////Paste the results of npx react-native info System: OS: Windows 10 10.0.22631 CPU: (8) x64 11th Gen Intel(R) Core(TM) i5-1145G7 @ 2.60GHz Memory: 1016.23 MB / 15.74 GB Binaries: Node: 16.13.0 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD npm: 10.8.2 - D:\Git\Mob_code\Baxter_Cloud_Gemflow_MobileApp\gem-mobile-app\node_modules.bin\npm.CMD Watchman: Not Found SDKs: Android SDK: Not Found Windows SDK: Not Found IDEs: Android Studio: AI-213.7172.25.2113.9123335 Visual Studio: Not Found Languages: Java: 11.0.16 npmPackages: @react-native-community/cli: Not Found react: 18.2.0 => 18.2.0 react-native: 0.71.6 => 0.71.6 react-native-windows: Not Found npmGlobalPackages: react-native: Not Found

//////////////the exact react-native-track-player version you are using "react-native-track-player": "^4.1.1",

Real device? Or simulator? Both

What OS are you running? windows 10

////////////////// i have implemented the code by refering doc https://rntp.dev/docs/basics/background-mode

lovegaoshi commented 2 months ago

its working as intended

By default, the audio will continue to play, not only when the app is suspended in the background, but also after the app is closed by the user. If that is not the desired behavior, you can disable it with the android.appKilledPlaybackBehavior property in updateOptions.

this is strictly referring to app close which is governed by android.appKilledPlaybackBehavior

if u want to stop when minimized u have to use a hook of AppState and register it in headlessJsTaskService or emit it via native.