Skip to content
TypeScript

fix(mobile): pause videos outside visible thread and PR content (#24268)

Julius Marmingebfc7177f9f54
diff --git a/apps/mobile/src/components/MediaVideoPlayer.tsx b/apps/mobile/src/components/MediaVideoPlayer.tsx
index 89b3aed219a..ea39cac15ba 100644
--- a/apps/mobile/src/components/MediaVideoPlayer.tsx
+++ b/apps/mobile/src/components/MediaVideoPlayer.tsx
@@ -1,8 +1,7 @@
-import { useIsFocused } from "@react-navigation/native";
import { useEvent } from "expo";
import { useVideoPlayer, VideoView } from "expo-video";
import { useEffect, useEffectEvent, useMemo, useRef, useState } from "react";
-import { AppState, Pressable, View } from "react-native";
+import { Pressable, View } from "react-native";
import { AppActivityIndicator } from "./ui/AppActivityIndicator";
import { AppText } from "./ui/AppText";
@@ -10,7 +9,7 @@ import { SymbolView } from "./ui/AppSymbol";
import { VideoThumbnailImage } from "./VideoThumbnailImage";
import { useMediaActions } from "../state/mediaActions";
import { type MediaActionsSource } from "../lib/mediaActionsSource";
-import { useFullscreenVideoOpen, useMediaAudioSessionHold } from "../lib/videoAudioSession";
+import { useMediaVideoPlayback } from "../lib/useMediaVideoPlayback";
import { MediaActionsMenu } from "./MediaActionsMenu";
import { createAudioPlaybackSession } from "../lib/audioSession";
@@ -19,13 +18,9 @@ function LoadedMediaVideo(props: {
readonly resolvePlaybackUri?: () => Promise<string | null>;
readonly playRequested: boolean;
readonly paused: boolean;
+ readonly visible: boolean;
readonly onPlaybackStart?: () => void;
}) {
- const focused = useIsFocused();
- const fullscreenVideoOpen = useFullscreenVideoOpen();
- const paused = props.paused || fullscreenVideoOpen;
- const active = useRef(focused && AppState.currentState === "active");
- const fullscreen = useRef(false);
const [attempt, setAttempt] = useState(0);
// Expo's Android player also reports completed playback as idle.
const [loadState, setLoadState] = useState<"pending" | "complete" | "error">("pending");
@@ -34,6 +29,8 @@ function LoadedMediaVideo(props: {
player.bufferOptions = { preferredForwardBufferDuration: 5 };
});
const playback = useMemo(() => createAudioPlaybackSession(player, true), [player]);
+ const { active, fullscreen, createPlayRequest, onFullscreenEnter, onFullscreenExit } =
+ useMediaVideoPlayback(player, props, playback);
const previousPlaybackRequested = useRef(false);
const onPlaybackStart = useEffectEvent(() => props.onPlaybackStart?.());
useEffect(() => {
@@ -64,31 +61,19 @@ function LoadedMediaVideo(props: {
playback.pause();
previousPlaybackRequested.current = false;
};
- }, [player, playback]);
+ }, [active, fullscreen, player, playback]);
const { status } = useEvent(player, "statusChange", { status: player.status });
- const { isPlaying } = useEvent(player, "playingChange", { isPlaying: player.playing });
- useMediaAudioSessionHold(isPlaying);
const loadSource = useEffectEvent(async (signal: AbortSignal) => {
+ const playIfUninterrupted = createPlayRequest();
const uri = props.resolvePlaybackUri ? await props.resolvePlaybackUri() : props.uri;
if (signal.aborted) return;
if (uri === null) throw new Error("Video unavailable");
playback.pause();
previousPlaybackRequested.current = false;
await player.replaceAsync({ uri, contentType: "progressive" });
- if (!signal.aborted && props.playRequested && active.current) await playback.play();
+ if (!signal.aborted && props.playRequested) await playIfUninterrupted();
});
- useEffect(() => {
- active.current = focused && !paused && AppState.currentState === "active";
- if (!focused || paused || (!active.current && !fullscreen.current)) playback.pause();
- // RN reports both leaving the app and Android fullscreen as background; native handling distinguishes them.
- const subscription = AppState.addEventListener("change", (state) => {
- active.current = focused && !paused && state === "active";
- if (state === "inactive" || (state === "background" && !fullscreen.current)) playback.pause();
- });
- return () => subscription.remove();
- }, [focused, playback, paused]);
-
useEffect(() => {
const controller = new AbortController();
// oxlint-disable-next-line react/set-state-in-effect -- Starting a native media load publishes pending before its async result.
@@ -115,12 +100,8 @@ function LoadedMediaVideo(props: {
nativeControls
contentFit="contain"
fullscreenOptions={{ enable: true }}
- onFullscreenEnter={() => {
- fullscreen.current = true;
- }}
- onFullscreenExit={() => {
- fullscreen.current = false;
- }}
+ onFullscreenEnter={onFullscreenEnter}
+ onFullscreenExit={onFullscreenExit}
allowsPictureInPicture={false}
/>
{loadState === "error" || (loadState === "complete" && status === "error") ? (
@@ -150,6 +131,7 @@ interface MediaVideoPlayerProps {
readonly name: string;
readonly thumbnailKey: string;
readonly thumbnailVisible?: boolean;
+ readonly visible?: boolean;
readonly unavailable?: boolean;
readonly expanded?: boolean;
readonly autoPlay?: boolean;
@@ -176,6 +158,7 @@ function MediaVideoPlayerContent(props: MediaVideoPlayerProps) {
resolvePlaybackUri={props.resolvePlaybackUri}
playRequested={!props.expanded || props.autoPlay === true}
paused={(props.paused ?? false) || mediaActions.sharing}
+ visible={props.visible ?? true}
onPlaybackStart={props.onPlaybackStart}
/>
) : (
diff --git a/apps/mobile/src/features/pull-requests/PullRequestMedia.tsx b/apps/mobile/src/features/pull-requests/PullRequestMedia.tsx
index 8f97b9c2289..58590229fbf 100644
--- a/apps/mobile/src/features/pull-requests/PullRequestMedia.tsx
+++ b/apps/mobile/src/features/pull-requests/PullRequestMedia.tsx
@@ -22,6 +22,8 @@ import {
type FilePreviewItem,
} from "../../components/FilePreviewModal";
+export const PullRequestMediaVisibleContext = createContext(true);
+
export const PullRequestMediaContext = createContext<{
readonly environmentId: EnvironmentId;
readonly cwd: string;
@@ -54,6 +56,7 @@ export function PullRequestMedia(props: {
readonly compact?: boolean;
}) {
const media = usePullRequestMediaUrl(props.url);
+ const visible = useContext(PullRequestMediaVisibleContext);
const context = useContext(PullRequestMediaContext);
const withGallery = useFilePreviewGallery();
const [image, setImage] = useState<FilePreviewSource | null>(null);
@@ -86,7 +89,7 @@ export function PullRequestMedia(props: {
<VideoAttachmentTile
name={name}
sourceIdentifier={props.url}
- thumbnailSource={media.uri}
+ thumbnailSource={visible ? media.uri : null}
style={{ width: 176, height: 112, borderRadius: 16 }}
onPress={() =>
setVideo({
@@ -105,6 +108,8 @@ export function PullRequestMedia(props: {
unavailable={media.unavailable}
name={name}
thumbnailKey={props.url}
+ thumbnailVisible={visible}
+ visible={visible}
resolvePlaybackUri={media.resolvePlaybackUri}
/>
)}
diff --git a/apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx b/apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx
index 81a33708c4a..3ceba8273c4 100644
--- a/apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx
+++ b/apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx
@@ -111,6 +111,7 @@ import {
} from "./PullRequestPresentation";
import { usePullRequestFilesSection } from "./PullRequestFiles";
import { PullRequestDescription } from "./PullRequestDescription";
+import { PullRequestMediaVisibleContext } from "./PullRequestMedia";
import { PullRequestMarkdownRepository } from "./PullRequestMarkdown";
import {
PullRequestStatusMenu,
@@ -795,7 +796,9 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestP
listAnimationsReady && !item.key.endsWith(":body") ? PR_ROW_EXIT : undefined
}
>
- {item.content}
+ <PullRequestMediaVisibleContext value={section === tab}>
+ {item.content}
+ </PullRequestMediaVisibleContext>
</Animated.View>
)}
recycleItems={false}
diff --git a/apps/mobile/src/features/threads/ThreadMarkdownVideo.tsx b/apps/mobile/src/features/threads/ThreadMarkdownVideo.tsx
index 11869a0fcb2..5f4b5ec263d 100644
--- a/apps/mobile/src/features/threads/ThreadMarkdownVideo.tsx
+++ b/apps/mobile/src/features/threads/ThreadMarkdownVideo.tsx
@@ -39,7 +39,7 @@ export function ThreadMarkdownVideo(props: {
name={source.name}
thumbnailKey={thumbnailKey}
thumbnailVisible={visible}
- paused={!visible}
+ visible={visible}
onPlaybackStart={props.onPlaybackStart}
unavailable={"resource" in source && asset._tag === "Failure"}
actionsSource={source.actionsSource}
diff --git a/apps/mobile/src/lib/useMediaVideoPlayback.test.tsx b/apps/mobile/src/lib/useMediaVideoPlayback.test.tsx
new file mode 100644
index 00000000000..703a1acd3ff
--- /dev/null
+++ b/apps/mobile/src/lib/useMediaVideoPlayback.test.tsx
@@ -0,0 +1,335 @@
+import { act, type ReactNode } from "react";
+import { createRoot } from "react-dom/client";
+import type { AppStateStatus } from "react-native";
+import { expect, it, vi } from "vite-plus/test";
+import { EnvironmentId } from "@t3tools/contracts";
+
+const mocks = vi.hoisted(() => ({
+ focused: true,
+ appState: "active" as AppStateStatus,
+ appStateListeners: new Set<(state: AppStateStatus) => void>(),
+ players: [] as ReturnType<typeof createPlayer>[],
+ refresh: vi.fn<() => Promise<string | null>>(),
+ replace: vi.fn<() => Promise<void>>(),
+ thumbnail: vi.fn<(key: string, source: unknown, signal: AbortSignal) => Promise<null>>(),
+}));
+vi.mock("@react-navigation/native", () => ({ useIsFocused: () => mocks.focused }));
+vi.mock("react-native", () => ({
+ Platform: { OS: "ios" },
+ StyleSheet: { absoluteFill: {} },
+ View: ({ children }: { children?: ReactNode }) => <div>{children}</div>,
+ Pressable: ({
+ children,
+ onPress,
+ accessibilityLabel,
+ }: {
+ children?: ReactNode;
+ onPress?: () => void;
+ accessibilityLabel?: string;
+ }) => (
+ <button aria-label={accessibilityLabel} onClick={onPress}>
+ {children}
+ </button>
+ ),
+ AppState: {
+ get currentState() {
+ return mocks.appState;
+ },
+ addEventListener: (_event: string, listener: (state: AppStateStatus) => void) => {
+ mocks.appStateListeners.add(listener);
+ return { remove: () => mocks.appStateListeners.delete(listener) };
+ },
+ },
+}));
+vi.mock("expo", async () => {
+ const { useSyncExternalStore } = await import("react");
+ return {
+ requireOptionalNativeModule: () => null,
+ useEvent: (player: ReturnType<typeof createPlayer>, event: string, initial: unknown) => {
+ const playing = useSyncExternalStore(player.subscribe, () => player.playing);
+ return event === "playingChange" ? { isPlaying: playing } : initial;
+ },
+ };
+});
+vi.mock("expo-video", async () => {
+ const { useState } = await import("react");
+ return {
+ useVideoPlayer: (
+ _source: unknown,
+ initialize: (player: ReturnType<typeof createPlayer>) => void,
+ ) =>
+ useState(() => {
+ const player = createPlayer();
+ initialize(player);
+ mocks.players.push(player);
+ return player;
+ })[0],
+ VideoView: (props: { onFullscreenEnter: () => void; onFullscreenExit: () => void }) => (
+ <div aria-label="Video">
+ <button aria-label="Enter fullscreen" onClick={props.onFullscreenEnter} />
+ <button aria-label="Exit fullscreen" onClick={props.onFullscreenExit} />
+ </div>
+ ),
+ };
+});
+vi.mock("expo-audio", () => ({
+ AudioModule: { setAudioSessionOwner: vi.fn() },
+ setAudioModeAsync: vi.fn().mockResolvedValue(undefined),
+ setIsAudioActiveAsync: vi.fn().mockResolvedValue(undefined),
+}));
+vi.mock("expo-image", () => ({ Image: () => null }));
+vi.mock("../components/ui/AppActivityIndicator", () => ({ AppActivityIndicator: () => null }));
+vi.mock("../components/ui/AppSymbol", () => ({ SymbolView: () => null }));
+vi.mock("../components/ui/AppText", () => ({
+ AppText: ({ children }: { children?: ReactNode }) => <span>{children}</span>,
+}));
+vi.mock("../components/MediaActionsMenu", () => ({
+ MediaActionsMenu: ({ children }: { children?: ReactNode }) => children,
+}));
+vi.mock("../components/ui/NativePresentation", () => ({
+ PresentationSource: ({ children }: { children?: ReactNode }) => children,
+}));
+vi.mock("../state/mediaActions", () => ({
+ useMediaActions: () => ({ actions: [], sharing: false }),
+}));
+vi.mock("../state/assets", () => ({
+ useAssetUrlState: () => ({ _tag: "Success", url: "https://media.example/clip.mp4" }),
+ useRefreshAssetUrl: () => mocks.refresh,
+}));
+vi.mock("./localAttachmentPreview", () => ({ loadLocalAttachmentPreview: vi.fn() }));
+vi.mock("./videoThumbnails", () => ({
+ cachedVideoThumbnail: () => null,
+ loadVideoThumbnail: mocks.thumbnail,
+}));
+vi.mock("../components/FilePreviewGallery", () => ({
+ useFilePreviewGallery: () => (value: unknown) => value,
+}));
+vi.mock("../components/FilePreviewModal", () => ({ FilePreviewModal: () => null }));
+vi.mock("../components/VideoPreviewModal", () => ({ VideoPreviewModal: () => null }));
+vi.mock("../features/threads/ThreadMarkdownImage", () => ({ ThreadMarkdownImageView: () => null }));
+
+import {
+ ThreadMarkdownVideo,
+ ThreadMediaVisibleContext,
+} from "../features/threads/ThreadMarkdownVideo";
+import {
+ PullRequestMedia,
+ PullRequestMediaContext,
+ PullRequestMediaVisibleContext,
+} from "../features/pull-requests/PullRequestMedia";
+
+function createPlayer() {
+ let playing = false;
+ const listeners = new Set<() => void>();
+ const playingListeners = new Set<(event: { isPlaying: boolean }) => void>();
+ const setPlaying = (next: boolean) => {
+ playing = next;
+ for (const listener of listeners) listener();
+ for (const listener of playingListeners) listener({ isPlaying: next });
+ };
+ return {
+ currentTime: 0,
+ status: "readyToPlay",
+ get playing() {
+ return playing;
+ },
+ play: vi.fn(() => setPlaying(true)),
+ pause: vi.fn(() => setPlaying(false)),
+ replaceAsync: vi.fn(() => mocks.replace()),
+ addListener(event: string, listener: (event: { isPlaying: boolean }) => void) {
+ if (event === "playingChange") playingListeners.add(listener);
+ return { remove: () => playingListeners.delete(listener) };
+ },
+ subscribe(listener: () => void) {
+ listeners.add(listener);
+ return () => listeners.delete(listener);
+ },
+ };
+}
+
+function setup(kind: "thread" | "PR", compact = false) {
+ (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
+ mocks.focused = true;
+ mocks.appState = "active";
+ mocks.players = [];
+ mocks.appStateListeners.clear();
+ mocks.refresh.mockReset().mockResolvedValue("https://media.example/clip.mp4");
+ mocks.replace.mockReset().mockResolvedValue();
+ mocks.thumbnail.mockReset().mockResolvedValue(null);
+ const container = document.createElement("div");
+ const root = createRoot(container);
+ const environmentId = EnvironmentId.make("test");
+ return {
+ render(visible = true) {
+ act(() =>
+ root.render(
+ kind === "thread" ? (
+ <ThreadMediaVisibleContext value={visible}>
+ <ThreadMarkdownVideo
+ source={{
+ type: "media",
+ name: "clip.mp4",
+ mimeType: "video/mp4",
+ environmentId,
+ resource: {
+ _tag: "github-media",
+ cwd: "/project",
+ url: "https://github.com/user-attachments/assets/video",
+ },
+ }}
+ />
+ </ThreadMediaVisibleContext>
+ ) : (
+ <PullRequestMediaContext value={{ environmentId, cwd: "/project" }}>
+ <PullRequestMediaVisibleContext value={visible}>
+ <PullRequestMedia
+ url="https://github.com/user-attachments/assets/video"
+ kind="video"
+ compact={compact}
+ />
+ </PullRequestMediaVisibleContext>
+ </PullRequestMediaContext>
+ ),
+ ),
+ );
+ },
+ async open() {
+ const button = container.querySelector("button");
+ expect(button).not.toBeNull();
+ await act(async () => button!.click());
+ expect(mocks.players).toHaveLength(1);
+ return mocks.players[0]!;
+ },
+ fullscreen(open: boolean) {
+ const button = container.querySelector<HTMLButtonElement>(
+ `[aria-label="${open ? "Enter" : "Exit"} fullscreen"]`,
+ );
+ expect(button).not.toBeNull();
+ act(() => button!.click());
+ },
+ appState(state: AppStateStatus) {
+ mocks.appState = state;
+ act(() => {
+ for (const listener of mocks.appStateListeners) listener(state);
+ });
+ },
+ [Symbol.dispose]() {
+ act(() => root.unmount());
+ },
+ };
+}
+
+it.each(["thread", "PR"] as const)(
+ "retains the %s player and position while hidden and requires deliberate resume",
+ async (kind) => {
+ using screen = setup(kind);
+ screen.render();
+ const player = await screen.open();
+ expect(player.playing).toBe(true);
+ player.currentTime = 37;
+ screen.render(false);
+ expect(player.playing).toBe(false);
+ screen.render(true);
+ expect(mocks.players).toEqual([player]);
+ expect(player.replaceAsync).toHaveBeenCalledTimes(1);
+ expect(player.currentTime).toBe(37);
+ expect(player.playing).toBe(false);
+ },
+);
+
+it.each(["thread", "PR"] as const)(
+ "does not start a hidden %s video when signing or native loading finishes late",
+ async (kind) => {
+ using screen = setup(kind);
+ const signed = Promise.withResolvers<string | null>();
+ const replaced = Promise.withResolvers<void>();
+ mocks.refresh.mockReturnValue(signed.promise);
+ mocks.replace.mockReturnValue(replaced.promise);
+ screen.render();
+ const player = await screen.open();
+ screen.render(false);
+ await act(async () => signed.resolve("https://media.example/renewed.mp4"));
+ expect(player.replaceAsync).toHaveBeenCalledTimes(1);
+ expect(player.play).not.toHaveBeenCalled();
+ await act(async () => replaced.resolve());
+ expect(player.play).not.toHaveBeenCalled();
+ screen.render(true);
+ expect(player.playing).toBe(false);
+ expect(player.replaceAsync).toHaveBeenCalledTimes(1);
+ },
+);
+
+it.each([false, true])(
+ "stops inactive PR thumbnail requests (compact: %s) and restarts on return",
+ async (compact) => {
+ using screen = setup("PR", compact);
+ screen.render(false);
+ expect(mocks.thumbnail).not.toHaveBeenCalled();
+ await act(async () => screen.render(true));
+ expect(mocks.thumbnail).toHaveBeenCalledTimes(1);
+ const signal = mocks.thumbnail.mock.calls[0]![2];
+ expect(signal.aborted).toBe(false);
+ screen.render(false);
+ expect(signal.aborted).toBe(true);
+ expect(mocks.thumbnail).toHaveBeenCalledTimes(1);
+ await act(async () => screen.render(true));
+ expect(mocks.thumbnail).toHaveBeenCalledTimes(2);
+ },
+);
+
+it("pauses on screen blur and app inactivity without resuming on return", async () => {
+ using screen = setup("thread");
+ screen.render();
+ const player = await screen.open();
+ for (const reason of ["blur", "inactive", "background"] as const) {
+ act(() => player.play());
+ player.currentTime = 37;
+ if (reason === "blur") {
+ mocks.focused = false;
+ screen.render();
+ } else screen.appState(reason);
+ expect(player.playing, reason).toBe(false);
+ mocks.focused = true;
+ screen.appState("active");
+ screen.render();
+ expect(player.playing, reason).toBe(false);
+ expect(player.currentTime).toBe(37);
+ }
+ expect(player.replaceAsync).toHaveBeenCalledTimes(1);
+});
+
+it.each(["thread", "PR"] as const)(
+ "keeps the %s play request cancelled when loading finishes after returning",
+ async (kind) => {
+ using screen = setup(kind);
+ const signed = Promise.withResolvers<string | null>();
+ const replaced = Promise.withResolvers<void>();
+ mocks.refresh.mockReturnValue(signed.promise);
+ mocks.replace.mockReturnValue(replaced.promise);
+ screen.render();
+ const player = await screen.open();
+ screen.render(false);
+ screen.render(true);
+ await act(async () => signed.resolve("https://media.example/renewed.mp4"));
+ await act(async () => replaced.resolve());
+ expect(player.replaceAsync).toHaveBeenCalledTimes(1);
+ expect(player.play).not.toHaveBeenCalled();
+ act(() => player.play());
+ expect(player.playing).toBe(true);
+ },
+);
+
+it("pauses when native fullscreen exits while the app remains in the background", async () => {
+ using screen = setup("thread");
+ screen.render();
+ const player = await screen.open();
+ player.currentTime = 37;
+ screen.fullscreen(true);
+ screen.appState("background");
+ expect(player.playing).toBe(true);
+ screen.fullscreen(false);
+ expect(player.playing).toBe(false);
+ screen.appState("active");
+ expect(player.playing).toBe(false);
+ expect(player.currentTime).toBe(37);
+});
diff --git a/apps/mobile/src/lib/useMediaVideoPlayback.ts b/apps/mobile/src/lib/useMediaVideoPlayback.ts
new file mode 100644
index 00000000000..d0950cd3ef9
--- /dev/null
+++ b/apps/mobile/src/lib/useMediaVideoPlayback.ts
@@ -0,0 +1,56 @@
+import { useIsFocused } from "@react-navigation/native";
+import { useEvent } from "expo";
+import type { VideoPlayer } from "expo-video";
+import { useCallback, useEffect, useRef } from "react";
+import { AppState } from "react-native";
+
+import { useFullscreenVideoOpen, useMediaAudioSessionHold } from "./videoAudioSession";
+
+export function useMediaVideoPlayback(
+ player: VideoPlayer,
+ options: { readonly paused: boolean; readonly visible?: boolean },
+ playback: { play(): Promise<void>; pause(): void },
+) {
+ const focused = useIsFocused();
+ const fullscreenVideoOpen = useFullscreenVideoOpen();
+ const paused = options.paused || fullscreenVideoOpen || options.visible === false;
+ const active = useRef(focused && !paused && AppState.currentState === "active");
+ const fullscreen = useRef(false);
+ const interruption = useRef(0);
+ const { isPlaying } = useEvent(player, "playingChange", { isPlaying: player.playing });
+ useMediaAudioSessionHold(isPlaying);
+
+ useEffect(() => {
+ active.current = focused && !paused && AppState.currentState === "active";
+ if (!active.current) interruption.current += 1;
+ if (!focused || paused || (!active.current && !fullscreen.current)) playback.pause();
+ // Native background handling distinguishes Android's fullscreen activity
+ // from leaving the app; React Native reports both as background.
+ const subscription = AppState.addEventListener("change", (state) => {
+ active.current = focused && !paused && state === "active";
+ if (!active.current) interruption.current += 1;
+ if (state === "inactive" || (state === "background" && !fullscreen.current)) playback.pause();
+ });
+ return () => subscription.remove();
+ }, [focused, playback, paused]);
+
+ const createPlayRequest = useCallback(() => {
+ const requestedAt = interruption.current;
+ const requestedWhileActive = active.current;
+ // Returning to the content must not revive playback interrupted during loading.
+ return () => {
+ if (requestedWhileActive && active.current && requestedAt === interruption.current)
+ return playback.play();
+ };
+ }, [playback]);
+
+ const onFullscreenEnter = useCallback(() => {
+ fullscreen.current = true;
+ }, []);
+ const onFullscreenExit = useCallback(() => {
+ fullscreen.current = false;
+ if (!active.current) playback.pause();
+ }, [playback]);
+
+ return { active, fullscreen, createPlayRequest, onFullscreenEnter, onFullscreenExit };
+}
diff --git a/apps/mobile/vite.config.ts b/apps/mobile/vite.config.ts
index ff26264ea29..3759b6c3ab6 100644
--- a/apps/mobile/vite.config.ts
+++ b/apps/mobile/vite.config.ts
@@ -4,6 +4,7 @@ import { defineConfig, normalizePath } from "vite-plus";
import "vite-plus/test/config";
const reactTests = [
+ "src/lib/useMediaVideoPlayback.test.tsx",
"src/features/pull-requests/usePullRequestEnvironmentFallback.test.tsx",
"src/lib/filePreview.test.ts",
"src/features/threads/thread-inspector-navigation.test.tsx",
diff --git a/scripts/effect-budget.json b/scripts/effect-budget.json
index 008ba170fd0..7a4e4a1e2f2 100644
--- a/scripts/effect-budget.json
+++ b/scripts/effect-budget.json
@@ -7,7 +7,7 @@
"apps/mobile/src/components/FilePreview.ios.tsx": 1,
"apps/mobile/src/components/FilePreview.tsx": 1,
"apps/mobile/src/components/FilePreviewModal.tsx": 5,
- "apps/mobile/src/components/MediaVideoPlayer.tsx": 3,
+ "apps/mobile/src/components/MediaVideoPlayer.tsx": 2,
"apps/mobile/src/components/PdfPreview.android.tsx": 1,
"apps/mobile/src/components/ProjectFavicon.tsx": 1,
"apps/mobile/src/components/VideoPreviewModal.ios.tsx": 6,
@@ -145,6 +145,7 @@
"apps/mobile/src/features/workspace/WorkspaceTabsContext.tsx": 1,
"apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsx": 1,
"apps/mobile/src/features/workspace/WorkspaceToolbar.tsx": 2,
+ "apps/mobile/src/lib/useMediaVideoPlayback.ts": 1,
"apps/mobile/src/lib/attachmentDocument.ts": 4,
"apps/mobile/src/lib/useDelayedStatus.ts": 2,
"apps/mobile/src/lib/useUiRuntimeMemoryWarningGc.ts": 1,