-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathGetPeaksExample.js
61 lines (55 loc) · 1.62 KB
/
GetPeaksExample.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import React from 'react';
import ReactWaves from '@dschoon/react-waves';
import africa from '../audio/africa.mp3';
export default class GetPeaksExample extends React.Component {
constructor(props) {
super(props);
this.state = {
audioPeaks: [],
};
}
onWaveformReady = ({ wavesurfer }) => {
wavesurfer.exportPCM(null, 1000, true, null).then(exportPCM => {
if (exportPCM) {
this.setState({ audioPeaks: exportPCM });
}
});
};
clickToCopy = () => {
let textArea = document.createElement('textarea');
textArea.value = this.state.audioPeaks;
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);
};
render() {
return (
<div>
<div className={'container example'} style={{ display: 'none' }}>
<div className="play button" onClick={() => { this.setState({ playing: !this.state.playing }) }}>
{ !this.state.playing ? '▶️' : '⏹' }
</div>
<ReactWaves
audioFile={africa}
className='react-waves'
options={{ backend: 'MediaElement' }}
onWaveformReady={this.onWaveformReady}
/>
</div>
<div>
{ this.state.audioPeaks.length ?
<div>
<div id='copy-btn'><button onClick={this.clickToCopy}>Copy</button></div>
<div id='audioPeaks'>
{this.state.audioPeaks}
</div>
</div>
: <div className='loader' />
}
</div>
</div>
)
}
}