-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathApp.jsx
184 lines (158 loc) · 3.95 KB
/
App.jsx
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import React, { Component } from 'react';
import {
ButtonToolbar,
Container,
Table,
ToggleButton,
ToggleButtonGroup
} from 'react-bootstrap';
import Point from './Point';
import Segment from './Segment';
import WaveformView from './WaveformView';
import './App.css';
const urls = {
1: {
audioUrl: '07030039.mp3',
audioContentType: 'audio/mpeg',
waveformDataUrl: '07030039.dat'
},
2: {
audioUrl: '07023003.mp3',
audioContentType: 'audio/mpeg',
waveformDataUrl: '07023003-2channel.dat'
}
};
class App extends Component {
constructor() {
super();
this.state = {
...urls[1]
};
}
render() {
return (
<React.Fragment>
<Container>
<h1>
Peaks.js React Example
</h1>
<p>
This is a simple example of how to use <a href="https://github.com/bbc/peaks.js">Peaks.js</a> in a React application.
</p>
<p>
Audio content is copyright BBC, from the <a href="https://sound-effects.bbcrewind.co.uk">BBC Sound Effects</a> library,
used under the terms of the <a href="https://sound-effects.bbcrewind.co.uk/licensing">RemArc Licence</a>.
</p>
<h3>Select audio</h3>
<ButtonToolbar>
<ToggleButtonGroup
type="radio"
name="options"
defaultValue={1}
onChange={this.handleSelectedAudioChange}>
<ToggleButton id={1} value={1}>Bird song</ToggleButton>
<ToggleButton id={2} value={2}>Car passing</ToggleButton>
</ToggleButtonGroup>
</ButtonToolbar>
<WaveformView
audioUrl={this.state.audioUrl}
audioContentType={this.state.audioContentType}
waveformDataUrl={this.state.waveformDataUrl}
setSegments={this.setSegments}
setPoints={this.setPoints}
/>
{this.renderSegments()}
{this.renderPoints()}
</Container>
</React.Fragment>
);
}
handleSelectedAudioChange = (e) => {
this.setState({
audioUrl: urls[e].audioUrl,
audioContentType: urls[e].audioContentType,
waveformDataUrl: urls[e].waveformDataUrl
});
};
setSegments = (segments) => {
this.setState({ segments });
};
renderSegments() {
const segments = this.state.segments;
if (!segments) {
return null;
}
if (segments.length === 0) {
return null;
}
return (
<React.Fragment>
<h2>Segments</h2>
<Table striped bordered>
<thead>
<tr>
<th>ID</th>
<th>Start time</th>
<th>End time</th>
<th>Label text</th>
</tr>
</thead>
<tbody>
{this.renderSegmentRows(segments)}
</tbody>
</Table>
</React.Fragment>
);
}
renderSegmentRows(segments) {
return segments.map((segment) =>
<Segment
id={segment.id}
key={segment.id}
startTime={segment.startTime}
endTime={segment.endTime}
labelText={segment.labelText}
/>
);
}
setPoints = (points) => {
this.setState({ points });
};
renderPoints() {
const points = this.state.points;
if (!points) {
return null;
}
if (points.length === 0) {
return null;
}
return (
<React.Fragment>
<h2>Points</h2>,
<Table striped bordered>
<thead>
<tr>
<th>ID</th>
<th>Time</th>
<th>Label text</th>
</tr>
</thead>
<tbody>
{this.renderPointRows(points)}
</tbody>
</Table>
</React.Fragment>
);
}
renderPointRows(points) {
return points.map((point) =>
<Point
id={point.id}
key={point.id}
time={point.time}
labelText={point.labelText}
/>
);
}
}
export default App;