mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-11 04:16:55 +00:00
- Drop buzz.js for wavesurfer.js - Wrapper in TypeScript / Webpack instead of Javascript / Gulp
64 lines
1.2 KiB
TypeScript
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');
|
|
|