From 86788ba91961d332691295bb082d3bf6bc99faec Mon Sep 17 00:00:00 2001 From: skalthoff <32023561+skalthoff@users.noreply.github.com> Date: Mon, 24 Nov 2025 18:26:05 -0800 Subject: [PATCH] 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> --- App.tsx | 6 ++++++ jest/setup/rntp.ts | 3 +++ 2 files changed, 9 insertions(+) diff --git a/App.tsx b/App.tsx index d90ca6e3..e576beba 100644 --- a/App.tsx +++ b/App.tsx @@ -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(() => { diff --git a/jest/setup/rntp.ts b/jest/setup/rntp.ts index 195b9dcf..2809c92a 100644 --- a/jest/setup/rntp.ts +++ b/jest/setup/rntp.ts @@ -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,