class AudioPlayer {
private state: AudioPlayerState;
private ui: any;
private volume: any;
private playlist: any;
private curSong: any;
constructor() {
this.state = new AudioPlayerState(this);
this.ui = new UserInterface();
this.ui.lockButton.onClick(this.clickLock);
this.ui.playButton.onClick(this.clickPlay);
this.ui.nextButton.onClick(this.clickNext);
this.ui.prevButton.onClick(this.clickPrevious);
}
changeState(state: AudioPlayerState) {
this.state = state;
}
clickLock() {
this.state.clickLock();
}
clickPlay() {
this.state.clickPlay();
}
clickNext() {
this.state.clickNext();
}
clickPrevious() {
this.state.clickPrevious();
}
// startPlayback() {}
// stopPlayback() {}
// nextSong() {}
// previousSong() {}
// fastForward(time) {}
// rewind(time) {}
}
abstract class AudioPlayerState {
constructor(player) {
this.player = player;
}
clickLock(): void;
clickPlay(): void;
clickNext(): void;
clickPrevious(): void;
}
class LockedState extends State {
clickLock() {
if (player.playing) {
player.changeState(new PlayingState(player));
} else {
player.changeState(new ReadyState(player));
}
}
clickPlay(): void {
/*undo anything*/
}
clickNext(): void {
/*undo anything*/
}
clickPrevious(): void {
/*undo anything*/
}
}
class ReadyState extends State {}
class PlayingState extends State {}