add appKilledPlaybackBehavior to stop playback and remove notification on app kill (#720)

* add appKilledPlaybackBehavior to stop playback and remove notification on app kill

* add additional RNTP mocks

---------

Co-authored-by: Violet Caulfield <42452695+anultravioletaurora@users.noreply.github.com>
This commit is contained in:
skalthoff
2025-11-24 18:26:05 -08:00
committed by GitHub
parent 279daa6a1d
commit 86788ba919
2 changed files with 9 additions and 0 deletions

View File

@@ -11,6 +11,7 @@ import { ONE_DAY, queryClient } from './src/constants/query-client'
import { GestureHandlerRootView } from 'react-native-gesture-handler'
import TrackPlayer, {
AndroidAudioContentType,
AppKilledPlaybackBehavior,
IOSCategory,
IOSCategoryOptions,
} from 'react-native-track-player'
@@ -63,6 +64,11 @@ export default function App(): React.JSX.Element {
notificationCapabilities: CAPABILITIES,
// Reduced interval for smoother progress tracking and earlier prefetch detection
progressUpdateEventInterval: PROGRESS_UPDATE_EVENT_INTERVAL,
// Stop playback and remove notification when app is killed to prevent battery drain
android: {
appKilledPlaybackBehavior:
AppKilledPlaybackBehavior.StopPlaybackAndRemoveNotification,
},
}),
)
.finally(() => {

View File

@@ -55,6 +55,9 @@ jest.mock('react-native-track-player', () => {
useTrackPlayerEvents: (events: Event[], handler: (variables: any) => void) => {
eventHandler = handler
},
AppKilledPlaybackBehavior: {
StopPlaybackAndRemoveNotification: 'stopPlaybackAndRemoveNotification',
},
Capability: {
Play: 1,
PlayFromId: 2,