get buttons working somewhat
This commit is contained in:
@@ -143,7 +143,9 @@ export function VideoPlayer({
|
|||||||
pointerEvents: 'none',
|
pointerEvents: 'none',
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<div ref={containerRef} style={{flex: 1}}>
|
<div
|
||||||
|
ref={containerRef}
|
||||||
|
style={{width: '100%', height: '100%', display: 'flex'}}>
|
||||||
<Controls
|
<Controls
|
||||||
videoRef={ref}
|
videoRef={ref}
|
||||||
active={active}
|
active={active}
|
||||||
@@ -184,8 +186,16 @@ function Controls({
|
|||||||
onScreen: boolean
|
onScreen: boolean
|
||||||
enterFullscreen: () => void
|
enterFullscreen: () => void
|
||||||
}) {
|
}) {
|
||||||
const {play, pause, playing, muted, togglePlayPause, currentTime, duration} =
|
const {
|
||||||
useVideoUtils(videoRef)
|
play,
|
||||||
|
pause,
|
||||||
|
playing,
|
||||||
|
muted,
|
||||||
|
toggleMute,
|
||||||
|
togglePlayPause,
|
||||||
|
currentTime,
|
||||||
|
duration,
|
||||||
|
} = useVideoUtils(videoRef)
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const {
|
const {
|
||||||
@@ -233,7 +243,7 @@ function Controls({
|
|||||||
<View
|
<View
|
||||||
style={[
|
style={[
|
||||||
a.w_full,
|
a.w_full,
|
||||||
a.px_xs,
|
a.px_sm,
|
||||||
a.pt_md,
|
a.pt_md,
|
||||||
a.pb_lg,
|
a.pb_lg,
|
||||||
a.absolute,
|
a.absolute,
|
||||||
@@ -253,9 +263,7 @@ function Controls({
|
|||||||
<View style={a.flex_1} />
|
<View style={a.flex_1} />
|
||||||
<Button
|
<Button
|
||||||
label={_(muted ? msg`Unmute` : msg`Mute`)}
|
label={_(muted ? msg`Unmute` : msg`Mute`)}
|
||||||
onPress={() => {
|
onPress={() => toggleMute()}
|
||||||
console.log('clicked mute btn')
|
|
||||||
}}
|
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
shape="round"
|
shape="round"
|
||||||
size="medium">
|
size="medium">
|
||||||
@@ -381,7 +389,7 @@ function useVideoUtils(ref: React.RefObject<HTMLVideoElement>) {
|
|||||||
current.removeEventListener('error', handlePause)
|
current.removeEventListener('error', handlePause)
|
||||||
current.removeEventListener('canplay', handleCanPlay)
|
current.removeEventListener('canplay', handleCanPlay)
|
||||||
}
|
}
|
||||||
}, [ref, playing])
|
}, [ref])
|
||||||
|
|
||||||
// to explain why I'm doing this in an effect - if you call play()
|
// to explain why I'm doing this in an effect - if you call play()
|
||||||
// before it's loaded, at least on firefox, it'll throw when you then
|
// before it's loaded, at least on firefox, it'll throw when you then
|
||||||
@@ -400,6 +408,12 @@ function useVideoUtils(ref: React.RefObject<HTMLVideoElement>) {
|
|||||||
}
|
}
|
||||||
}, [playing, ref, canPlay])
|
}, [playing, ref, canPlay])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!ref.current) return
|
||||||
|
|
||||||
|
ref.current.muted = muted
|
||||||
|
}, [muted, ref])
|
||||||
|
|
||||||
const play = () => {
|
const play = () => {
|
||||||
setPlaying(true)
|
setPlaying(true)
|
||||||
}
|
}
|
||||||
@@ -412,5 +426,28 @@ function useVideoUtils(ref: React.RefObject<HTMLVideoElement>) {
|
|||||||
setPlaying(p => !p)
|
setPlaying(p => !p)
|
||||||
}
|
}
|
||||||
|
|
||||||
return {play, pause, togglePlayPause, duration, currentTime, playing, muted}
|
const mute = () => {
|
||||||
|
setMuted(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
const unmute = () => {
|
||||||
|
setMuted(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
const toggleMute = () => {
|
||||||
|
setMuted(m => !m)
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
play,
|
||||||
|
pause,
|
||||||
|
togglePlayPause,
|
||||||
|
duration,
|
||||||
|
currentTime,
|
||||||
|
playing,
|
||||||
|
muted,
|
||||||
|
mute,
|
||||||
|
unmute,
|
||||||
|
toggleMute,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user