-
Notifications
You must be signed in to change notification settings - Fork 154
/
Copy pathTapSidesToSeek.tsx
44 lines (34 loc) · 1.32 KB
/
TapSidesToSeek.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { useRef } from 'react';
import { usePlayerContext } from '@vime/react';
import './TapSidesToSeek.css';
function TapSidesToSeek() {
/**
* We need a reference to a DOM element so the Vime hooks work as they rely on dispatching
* custom DOM events.
*/
const ref = useRef(null);
// Little utility hook to get the current player, incase you need to call a method.
// *** -> const player = usePlayer(ref);
const [currentTime, setCurrentTime] = usePlayerContext(ref, 'currentTime', 0);
const [duration] = usePlayerContext(ref, 'duration', -1);
const [isVideoView] = usePlayerContext(ref, 'isVideoView', false);
const [isPlaybackReady] = usePlayerContext(ref, 'playbackReady', false);
const onSeekBackward = () => {
if (currentTime < 5) return;
// We are dispatching an update to the player to change the `currentTime` property.
setCurrentTime(currentTime - 5);
};
const onSeekForward = () => {
if (currentTime > duration - 5) return;
setCurrentTime(currentTime + 5);
};
if (!isVideoView || !isPlaybackReady) return null;
return (
<div ref={ref} className="tapSidesToSeek">
<div className="tapTarget" onClick={onSeekBackward} />
<div style={{ flex: 1 }} />
<div className="tapTarget" onClick={onSeekForward} />
</div>
);
}
export default TapSidesToSeek;