V3.4 Release: Prevent screen sleep during playback (Web & Android TV)

This commit is contained in:
vndangkhoa 2026-02-16 08:45:53 +07:00
parent d22f14df5c
commit f1bbe53ba6
2 changed files with 9 additions and 2 deletions

View file

@ -167,6 +167,7 @@ fun PlayerScreen(
setShowNextButton(false)
setShowPreviousButton(false)
controllerAutoShow = true
keepScreenOn = true // Prevent screen sleep during playback
layoutParams = FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT

View file

@ -88,6 +88,7 @@ export const useWatchMovie = (slug: string | undefined, episode: string | undefi
let wakeLock: any = null;
const requestWakeLock = async () => {
if (wakeLock !== null) return;
try {
if ('wakeLock' in navigator) {
wakeLock = await (navigator as any).wakeLock.request('screen');
@ -105,7 +106,7 @@ export const useWatchMovie = (slug: string | undefined, episode: string | undefi
wakeLock = null;
// console.log('Wake Lock released');
} catch (err) {
console.warn('Wake Lock release failed:', err);
// console.warn('Wake Lock release failed:', err);
}
}
};
@ -119,6 +120,11 @@ export const useWatchMovie = (slug: string | undefined, episode: string | undefi
video.addEventListener('pause', onPause);
video.addEventListener('ended', onEnded);
// If already playing (HLS might auto-start before this effect)
if (!video.paused) {
requestWakeLock();
}
// Re-acquire on visibility change if playing
const onVisibilityChange = () => {
if (document.visibilityState === 'visible' && !video.paused) {
@ -135,7 +141,7 @@ export const useWatchMovie = (slug: string | undefined, episode: string | undefi
releaseWakeLock();
};
}
}, [source]); // Re-run when source changes (new video loaded)
}, [source]);
return {
movie,