@@ -10,6 +10,7 @@ import { SymbolView } from "./AppSymbol";
1010import { VideoThumbnailImage } from "./VideoThumbnailImage" ;
1111import { useMediaActions } from "../state/mediaActions" ;
1212import { type MediaActionsSource } from "../lib/mediaActionsSource" ;
13+ import { useFullscreenVideoOpen , useMediaAudioSessionHold } from "../lib/videoAudioSession" ;
1314import { MediaActionsMenu } from "./MediaActionsMenu" ;
1415
1516/** Loads only after Play or opening the viewer. Source replacement never starts playback itself. */
@@ -20,6 +21,8 @@ function LoadedMediaVideo(props: {
2021 readonly paused : boolean ;
2122} ) {
2223 const focused = useIsFocused ( ) ;
24+ const fullscreenVideoOpen = useFullscreenVideoOpen ( ) ;
25+ const paused = props . paused || fullscreenVideoOpen ;
2326 const active = useRef ( focused && AppState . currentState === "active" ) ;
2427 const fullscreen = useRef ( false ) ;
2528 const [ attempt , setAttempt ] = useState ( 0 ) ;
@@ -30,6 +33,8 @@ function LoadedMediaVideo(props: {
3033 player . bufferOptions = { preferredForwardBufferDuration : 5 } ;
3134 } ) ;
3235 const { status } = useEvent ( player , "statusChange" , { status : player . status } ) ;
36+ const { isPlaying } = useEvent ( player , "playingChange" , { isPlaying : player . playing } ) ;
37+ useMediaAudioSessionHold ( isPlaying ) ;
3338 const loadSource = useEffectEvent ( async ( signal : AbortSignal ) => {
3439 const uri = props . resolvePlaybackUri ? await props . resolvePlaybackUri ( ) : props . uri ;
3540 if ( signal . aborted ) return ;
@@ -40,16 +45,16 @@ function LoadedMediaVideo(props: {
4045 } ) ;
4146
4247 useEffect ( ( ) => {
43- active . current = focused && ! props . paused && AppState . currentState === "active" ;
44- if ( ! focused || props . paused || ( ! active . current && ! fullscreen . current ) ) player . pause ( ) ;
48+ active . current = focused && ! paused && AppState . currentState === "active" ;
49+ if ( ! focused || paused || ( ! active . current && ! fullscreen . current ) ) player . pause ( ) ;
4550 // Native background handling distinguishes Android's fullscreen activity
4651 // from leaving the app; React Native reports both as background.
4752 const subscription = AppState . addEventListener ( "change" , ( state ) => {
48- active . current = focused && ! props . paused && state === "active" ;
53+ active . current = focused && ! paused && state === "active" ;
4954 if ( state === "inactive" || ( state === "background" && ! fullscreen . current ) ) player . pause ( ) ;
5055 } ) ;
5156 return ( ) => subscription . remove ( ) ;
52- } , [ focused , player , props . paused ] ) ;
57+ } , [ focused , player , paused ] ) ;
5358
5459 useEffect ( ( ) => {
5560 const controller = new AbortController ( ) ;
0 commit comments