Skip to content

Commit c1c2df7

Browse files
committed
install and configure wavesurfer.js
1 parent 0d93676 commit c1c2df7

File tree

6 files changed

+8081
-2
lines changed

6 files changed

+8081
-2
lines changed

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"cSpell.words": ["wavesurfer"]
3+
}

components/VideoArticle.jsx

+35-2
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,23 @@ import { parseSubs } from 'frazy-parser'
99
import { useRef, useEffect } from 'react'
1010
import useCaptions from './useCaptions'
1111
import usePlayer from './usePlayer'
12+
import peaks from './peaks'
13+
import initWavesurfer from '../wavesurfer'
1214

1315
const VideoInfo = props => {
1416
const {
1517
title,
1618
keywords,
17-
captionTracks,
19+
captionTracks: captionTracksYoutube,
1820
urlVideo,
1921
urlAudio,
2022
thumbnails,
2123
description,
2224
image: poster,
2325
setDisplayMode,
26+
displayMode
27+
} = props
28+
2429
const {
2530
captionTracks,
2631
captions,
@@ -32,6 +37,29 @@ const VideoInfo = props => {
3237
} = useCaptions(captionTracksYoutube)
3338

3439
const mediaRef = useRef(null)
40+
const audioRef = useRef(null)
41+
const waveformRef = useRef(null)
42+
const timelineRef = useRef(null)
43+
const wavesurferRef = useRef(null)
44+
45+
const { phrases: mainPhrases } = captions[selectedLangs[0] || 'en'] || {}
46+
47+
useEffect(() => {
48+
const initWavesurfer0 = async () => {
49+
const wavesurfer = await initWavesurfer({
50+
waveformContainer: waveformRef.current,
51+
timelineContainer: timelineRef.current,
52+
regions: mainPhrases,
53+
mediaElement: mediaRef.current,
54+
peaks
55+
})
56+
wavesurferRef.current = wavesurfer
57+
console.log('wavesurfer')
58+
console.log(wavesurfer)
59+
}
60+
initWavesurfer0()
61+
}, [])
62+
3563
const { onTimeUpdate, currentPhraseNum } = usePlayer({
3664
media: mediaRef.current,
3765
waveformContainer: waveformRef.current,
@@ -57,6 +85,8 @@ const VideoInfo = props => {
5785
ref={mediaRef}
5886
controls
5987
src={urlVideo}
88+
// src='http://localhost:3000/videoplayback.m4a'
89+
// src='http://localhost:3000/nevzuk.mp4'
6090
poster={poster}
6191
style={{ width: '100%' }}
6292
onTimeUpdate={onTimeUpdate}
@@ -65,7 +95,7 @@ const VideoInfo = props => {
6595

6696
const audioBlock = (
6797
<div style={styles.block}>
68-
<audio controls src={urlAudio} style={{ width: '100%' }} />
98+
<audio ref={audioRef} controls src={urlAudio} style={{ width: '100%' }} />
6999
</div>
70100
)
71101

@@ -153,6 +183,9 @@ const VideoInfo = props => {
153183
>
154184
{videoBlock}
155185
</div>
186+
<div>{currentPhraseNum}</div>
187+
<div ref={waveformRef} />
188+
<div ref={timelineRef} />
156189
<div style={styles.block}>
157190
<ShowingModeSwitcher
158191
displayMode={displayMode}

0 commit comments

Comments
 (0)