/
audio_clip.js
40 lines (32 loc) · 944 Bytes
/
audio_clip.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
var React = require("react");
module.exports = React.createClass({
displayName: "ReactKinetophoneAudioClip",
componentDidMount: function() {
this.audio = new Audio();
this.audio.src = this.props.src;
var start = this.props.start,
offset = this.props.currentTime - start;
this.audio.currentTime = offset / 1000;
if (this.props.playing) {
this.audio.play();
}
},
componentWillUnmount: function() {
this.audio.pause();
this.audio = null;
},
componentWillReceiveProps: function(props) {
if (this.props.playing !== props.playing) {
this.audio[props.playing ? "play" : "pause"]();
}
this.audio.playbackRate = this.props.playbackRate;
if (this.props.lastSeek !== props.lastSeek) {
var start = props.start,
offset = props.currentTime - start;
this.audio.currentTime = offset / 1000;
}
},
render: function() {
return null;
}
});