MCPcopy Create free account
hub / github.com/cookpete/react-player / App

Function App

examples/react/src/App.tsx:9–584  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7import Duration from './Duration';
8
9const App = () => {
10 const playerRef = useRef<HTMLVideoElement | null>(null);
11 const urlInputRef = useRef<HTMLInputElement | null>(null);
12
13 const initialState = {
14 src: undefined,
15 pip: false,
16 playing: false,
17 controls: false,
18 light: false,
19 volume: 1,
20 muted: false,
21 played: 0,
22 loaded: 0,
23 duration: 0,
24 playbackRate: 1.0,
25 loop: false,
26 seeking: false,
27 loadedSeconds: 0,
28 playedSeconds: 0,
29 };
30
31 type PlayerState = Omit<typeof initialState, 'src'> & {
32 src?: string;
33 };
34
35 const [state, setState] = useState<PlayerState>(initialState);
36
37 const load = (src?: string) => {
38 setState(prevState => ({
39 ...prevState,
40 src,
41 played: 0,
42 loaded: 0,
43 pip: false,
44 }));
45 };
46
47 const handlePlayPause = () => {
48 setState(prevState => ({ ...prevState, playing: !prevState.playing }));
49 };
50
51 const handleStop = () => {
52 setState(prevState => ({ ...prevState, src: undefined, playing: false }));
53 };
54
55 const handleToggleControls = () => {
56 setState(prevState => ({ ...prevState, controls: !prevState.controls }));
57 };
58
59 const handleToggleLight = () => {
60 setState(prevState => ({ ...prevState, light: !prevState.light }));
61 };
62
63 const handleToggleLoop = () => {
64 setState(prevState => ({ ...prevState, loop: !prevState.loop }));
65 };
66

Callers

nothing calls this directly

Calls 1

renderLoadButtonFunction · 0.85

Tested by

no test coverage detected