Files
artcraft/typescript/waveform.ts
T
Brandon Thomas 990faf3092 Add a WaveForm UI component (WaveSufer)
- Drop buzz.js for wavesurfer.js
- Wrapper in TypeScript / Webpack instead of Javascript / Gulp
2016-09-10 17:55:19 -04:00

64 lines
1.2 KiB
TypeScript

// FIXME: no type declarations exist.
declare var WaveSurfer: any;
type WaveSurfer = any;
export class WaveformPlayer {
wavesurfer: WaveSurfer;
constructor(css_selector: string) {
this.wavesurfer = WaveSurfer.create({
container: css_selector,
waveColor: 'teal',
progressColor: 'purple'
});
}
/** Load the wav url. */
load(wav_url: string) {
this.wavesurfer.load(wav_url);
}
/** Load the wav url and immediately play it. */
loadAndPlay(wav_url: string) {
let that = this;
this.load(wav_url);
this.wavesurfer.on('ready', function () {
that.wavesurfer.play();
});
}
/** In place pause. */
pause() {
this.wavesurfer.pause();
}
/** Resume playing at current position. */
play() {
this.wavesurfer.play();
}
/** Toggle play/pause states. */
toggle() {
if (this.wavesurfer.isPlaying()) {
this.pause();
} else {
this.play();
}
}
/** Stop and return to the beginning. */
stop() {
this.wavesurfer.stop();
}
/** Stop and clear the waveform data. */
clear() {
this.wavesurfer.empty();
}
}
window['waveform_player'] = new WaveformPlayer('#waveform');