diff options
-rw-r--r-- | tape-deck.js | 50 |
1 files changed, 19 insertions, 31 deletions
diff --git a/tape-deck.js b/tape-deck.js index 7362feb..14524de 100644 --- a/tape-deck.js +++ b/tape-deck.js @@ -13,11 +13,26 @@ let TapeDeck = { go: function () { this.elem.src = this.images.go; this.isPlaying = true; + this.playButton.toggle(); }, - stop: function () { + start: function () { + this.hasStarted = true; + this.playButton.initSound.onended = (event) => { Cassette.play(); }; + this.playButton.initSound.play(); + this.go(); + }, + pause: function () { + this.playButton.toggle(); + this.playButton.pressSound.play(); + Cassette.pause(); this.elem.src = this.images.stop; this.isPlaying = false; }, + resume: function () { + this.playButton.pressSound.play(); + this.go(); + Cassette.play(); + }, playButton: { elem: document.getElementById("play-button"), state: "off", @@ -37,38 +52,11 @@ let TapeDeck = { } }; -function start() { - const btn = TapeDeck.playButton; - - TapeDeck.hasStarted = true; - btn.toggle(); - btn.initSound.onended = (event) => { Cassette.play(); }; - btn.initSound.play(); -} - -function pause() { - const btn = TapeDeck.playButton; - - btn.toggle(); - btn.pressSound.play(); - Cassette.pause(); - TapeDeck.stop(); -} - -function resume() { - const btn = TapeDeck.playButton; - - btn.pressSound.play(); - btn.toggle(); - Cassette.play(); -} - // button onclick points here function play() { - if (TapeDeck.isPlaying) { pause(); return; } + if (TapeDeck.isPlaying) { TapeDeck.pause(); return; } - TapeDeck.hasStarted ? resume() : start(); - TapeDeck.go(); + TapeDeck.hasStarted ? TapeDeck.resume() : TapeDeck.start(); } function reset() { @@ -102,7 +90,7 @@ function formatTrackData(track) { } if (track.link) { - string = string.concat(` - ${track.link}`) + string = string.concat(` - ${track.link}`); } return string; |