Skip to content

Commit

Permalink
Move queueing to MusicPlayer
Browse files Browse the repository at this point in the history
  • Loading branch information
pomle committed Apr 2, 2020
1 parent 1e251a7 commit 47440b3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 2 additions & 6 deletions public/js/MusicController.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ export default class MusicController {

playHurryTheme() {
const audio = this.player.playTrack('hurry');
audio.loop = false;
const next = () => this.playTheme(1.2);
audio.addEventListener('ended', () => {
next();
audio.removeEventListener('ended', next);
});
this.player.waitForEnd(audio)
.then(() => this.playTheme(1.2));
}
}
7 changes: 7 additions & 0 deletions public/js/MusicPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@ export default class MusicPlayer {
audio.play();
return audio;
}

waitForEnd(audio) {
audio.loop = false;
return new Promise(resolve => {
audio.addEventListener('ended', resolve, {once: true});
});
}
}

0 comments on commit 47440b3

Please sign in to comment.