Spaces:
Running
Running
File size: 1,764 Bytes
6bcb42f |
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 |
import React from 'react';
import PropTypes from 'prop-types';
import bindAll from 'lodash.bindall';
import PlaybackStepComponent from '../components/record-modal/playback-step.jsx';
import AudioBufferPlayer from '../lib/audio/audio-buffer-player.js';
class PlaybackStep extends React.Component {
constructor (props) {
super(props);
bindAll(this, [
'handlePlay',
'handleStopPlaying'
]);
}
componentDidMount () {
this.audioBufferPlayer = new AudioBufferPlayer(this.props.samples, this.props.sampleRate);
}
componentWillUnmount () {
this.audioBufferPlayer.stop();
}
handlePlay () {
this.audioBufferPlayer.play(
this.props.trimStart,
this.props.trimEnd,
this.props.onSetPlayhead,
this.props.onStopPlaying
);
this.props.onPlay();
}
handleStopPlaying () {
this.audioBufferPlayer.stop();
this.props.onStopPlaying();
}
render () {
const {
sampleRate, // eslint-disable-line no-unused-vars
onPlay, // eslint-disable-line no-unused-vars
onStopPlaying, // eslint-disable-line no-unused-vars
onSetPlayhead, // eslint-disable-line no-unused-vars
...componentProps
} = this.props;
return (
<PlaybackStepComponent
onPlay={this.handlePlay}
onStopPlaying={this.handleStopPlaying}
{...componentProps}
/>
);
}
}
PlaybackStep.propTypes = {
sampleRate: PropTypes.number.isRequired,
samples: PropTypes.instanceOf(Float32Array).isRequired,
...PlaybackStepComponent.propTypes
};
export default PlaybackStep;
|