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) setShowNextButton(false)
setShowPreviousButton(false) setShowPreviousButton(false)
controllerAutoShow = true controllerAutoShow = true
keepScreenOn = true // Prevent screen sleep during playback
layoutParams = FrameLayout.LayoutParams( layoutParams = FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT,
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; let wakeLock: any = null;
const requestWakeLock = async () => { const requestWakeLock = async () => {
if (wakeLock !== null) return;
try { try {
if ('wakeLock' in navigator) { if ('wakeLock' in navigator) {
wakeLock = await (navigator as any).wakeLock.request('screen'); wakeLock = await (navigator as any).wakeLock.request('screen');
@ -105,7 +106,7 @@ export const useWatchMovie = (slug: string | undefined, episode: string | undefi
wakeLock = null; wakeLock = null;
// console.log('Wake Lock released'); // console.log('Wake Lock released');
} catch (err) { } 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('pause', onPause);
video.addEventListener('ended', onEnded); 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 // Re-acquire on visibility change if playing
const onVisibilityChange = () => { const onVisibilityChange = () => {
if (document.visibilityState === 'visible' && !video.paused) { if (document.visibilityState === 'visible' && !video.paused) {
@ -135,7 +141,7 @@ export const useWatchMovie = (slug: string | undefined, episode: string | undefi
releaseWakeLock(); releaseWakeLock();
}; };
} }
}, [source]); // Re-run when source changes (new video loaded) }, [source]);
return { return {
movie, movie,