Files
artcraft/frontend/audio.ts
T
2016-10-25 05:05:21 -04:00

35 lines
613 B
TypeScript

// Copyright (c) 2016 Brandon Thomas <bt@brand.io, echelon@gmail.com>
declare var buzz: any; // TODO: static types.
import { talk, stopTalking } from "./animation";
export default class Audio {
sound: any;
constructor() {
this.sound = null;
}
playUrl(url: string) {
this.stop();
this.sound = new buzz.sound(url);
this.sound.play();
this.sound.bind('play playing', function() {
talk(); // UI
});
this.sound.bind('error ended pause', function() {
stopTalking(); // UI
});
}
stop() {
if (this.sound != null) {
this.sound.stop();
}
}
}