File tree 3 files changed +58
-2
lines changed
3 files changed +58
-2
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import Thumbnails from './video/Thumbnails'
6
6
import ShowingModeSwitcher from './DisplayModeSwitcher'
7
7
import Phrases from './video/Phrases'
8
8
import { parseSubs } from 'frazy-parser'
9
+ import { useRef , useEffect } from 'react'
9
10
import useCaptions from './useCaptions'
10
11
import usePlayer from './usePlayer'
11
12
@@ -31,6 +32,11 @@ const VideoInfo = props => {
31
32
} = useCaptions ( captionTracksYoutube )
32
33
33
34
const mediaRef = useRef ( null )
35
+ const { onTimeUpdate , currentPhraseNum } = usePlayer ( {
36
+ media : mediaRef . current ,
37
+ waveformContainer : waveformRef . current ,
38
+ phrases : mainPhrases
39
+ } )
34
40
35
41
const titleBlock = (
36
42
< div style = { styles . block } >
@@ -53,6 +59,7 @@ const VideoInfo = props => {
53
59
src = { urlVideo }
54
60
poster = { poster }
55
61
style = { { width : '100%' } }
62
+ onTimeUpdate = { onTimeUpdate }
56
63
> </ video >
57
64
)
58
65
Original file line number Diff line number Diff line change
1
+ // import WaveSurfer from 'wavesurfer.js'
2
+ // import RegionsPlugin from 'wavesurfer.js/dist/plugin/wavesurfer.regions.min'
3
+ import { useEffect , useRef , useState } from 'react'
4
+
5
+ export default function usePlayer ( { media, phrases = [ ] , waveformContainer } ) {
6
+ const [ playerState , setPlayerState ] = useState ( {
7
+ isPlaying : false ,
8
+ currentTime : 0 ,
9
+ duration : 0 ,
10
+ isReady : false ,
11
+ playbackRate : 1 ,
12
+ currentPhraseNum : 0 ,
13
+ hideVideo : false ,
14
+ playOnePhrase : false ,
15
+ start : 0 ,
16
+ end : 1 ,
17
+ media,
18
+ phrases
19
+ } )
20
+
21
+ const wafesurferRef = useRef ( null )
22
+
23
+ const { currentPhraseNum } = playerState
24
+
25
+ const onTimeUpdate = event => {
26
+ //setPlayerState(oldState => ({...oldState, curre}))
27
+ const {
28
+ target : { currentTime }
29
+ } = event
30
+
31
+ const { end : currentPhaseEnd } = phrases [ currentPhraseNum ] || { }
32
+
33
+ if (
34
+ currentTime > currentPhaseEnd &&
35
+ currentPhraseNum < phrases . length - 1
36
+ ) {
37
+ setPlayerState ( prevState => ( {
38
+ ...prevState ,
39
+ currentPhraseNum : currentPhraseNum + 1
40
+ } ) )
41
+ }
42
+ }
43
+
44
+ return { onTimeUpdate, currentPhraseNum, wavesurfer : wafesurferRef . current }
45
+ }
Original file line number Diff line number Diff line change @@ -28,8 +28,12 @@ const Phrases = props => {
28
28
< div className = { styles . playButton } >
29
29
< IconButton
30
30
onClick = { ( ) => {
31
- mediaRef . currentTime = start
32
- mediaRef . paused ? mediaRef . play ( ) : mediaRef . pause ( )
31
+ if ( mediaRef . paused ) {
32
+ mediaRef . currentTime = start
33
+ mediaRef . play ( )
34
+ } else {
35
+ mediaRef . pause ( )
36
+ }
33
37
} }
34
38
style = { { fontSize : '0.7rem' , padding : 1 , color : 'silver' } }
35
39
>
You can’t perform that action at this time.
0 commit comments