change quality based on focused state
This commit is contained in:
@@ -113,15 +113,6 @@ export function VideoPlayer({
|
|||||||
}
|
}
|
||||||
}, [source, hls])
|
}, [source, hls])
|
||||||
|
|
||||||
// use minimal quality when not active
|
|
||||||
useEffect(() => {
|
|
||||||
if (active) {
|
|
||||||
hls.nextLevel = -1
|
|
||||||
} else {
|
|
||||||
hls.nextLevel = 0
|
|
||||||
}
|
|
||||||
}, [hls, active])
|
|
||||||
|
|
||||||
const enterFullscreen = useCallback(() => {
|
const enterFullscreen = useCallback(() => {
|
||||||
if (containerRef.current) {
|
if (containerRef.current) {
|
||||||
containerRef.current.requestFullscreen()
|
containerRef.current.requestFullscreen()
|
||||||
@@ -151,6 +142,7 @@ export function VideoPlayer({
|
|||||||
/>
|
/>
|
||||||
<Controls
|
<Controls
|
||||||
videoRef={ref}
|
videoRef={ref}
|
||||||
|
hls={hls}
|
||||||
active={active}
|
active={active}
|
||||||
setActive={setActive}
|
setActive={setActive}
|
||||||
focused={focused}
|
focused={focused}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
import type Hls from 'hls.js'
|
||||||
|
|
||||||
export function Controls({}: {
|
export function Controls({}: {
|
||||||
videoRef: React.RefObject<HTMLVideoElement>
|
videoRef: React.RefObject<HTMLVideoElement>
|
||||||
|
hls: Hls
|
||||||
active: boolean
|
active: boolean
|
||||||
setActive: () => void
|
setActive: () => void
|
||||||
focused: boolean
|
focused: boolean
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {Pressable, View} from 'react-native'
|
|||||||
import Animated, {FadeIn, FadeOut} from 'react-native-reanimated'
|
import Animated, {FadeIn, FadeOut} from 'react-native-reanimated'
|
||||||
import {msg, Trans} from '@lingui/macro'
|
import {msg, Trans} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
|
import type Hls from 'hls.js'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
useAutoplayDisabled,
|
useAutoplayDisabled,
|
||||||
@@ -29,6 +30,7 @@ import {Text} from '#/components/Typography'
|
|||||||
|
|
||||||
export function Controls({
|
export function Controls({
|
||||||
videoRef,
|
videoRef,
|
||||||
|
hls,
|
||||||
active,
|
active,
|
||||||
setActive,
|
setActive,
|
||||||
focused,
|
focused,
|
||||||
@@ -37,6 +39,7 @@ export function Controls({
|
|||||||
enterFullscreen,
|
enterFullscreen,
|
||||||
}: {
|
}: {
|
||||||
videoRef: React.RefObject<HTMLVideoElement>
|
videoRef: React.RefObject<HTMLVideoElement>
|
||||||
|
hls: Hls
|
||||||
active: boolean
|
active: boolean
|
||||||
setActive: () => void
|
setActive: () => void
|
||||||
focused: boolean
|
focused: boolean
|
||||||
@@ -104,6 +107,16 @@ export function Controls({
|
|||||||
}
|
}
|
||||||
}, [onScreen, pause, active, play, autoplayDisabled])
|
}, [onScreen, pause, active, play, autoplayDisabled])
|
||||||
|
|
||||||
|
// use minimal quality when not focused
|
||||||
|
useEffect(() => {
|
||||||
|
if (focused) {
|
||||||
|
// auto decide quality based on network conditions
|
||||||
|
hls.nextLevel = -1
|
||||||
|
} else {
|
||||||
|
hls.nextLevel = 0
|
||||||
|
}
|
||||||
|
}, [hls, focused])
|
||||||
|
|
||||||
// clicking on any button should focus the player, if it's not already focused
|
// clicking on any button should focus the player, if it's not already focused
|
||||||
const drawFocus = useCallback(() => {
|
const drawFocus = useCallback(() => {
|
||||||
if (!active) {
|
if (!active) {
|
||||||
|
|||||||
Reference in New Issue
Block a user