« get me outta code hell

Escape to stop playing current track - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
path: root/ui.js
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2018-06-04 23:47:18 -0300
committerFlorrie <towerofnix@gmail.com>2018-06-04 23:47:24 -0300
commit8207422459bce7fc3ca3f919ef426e54eaa826b0 (patch)
tree6746d637ae48c4fdc7a135c92db3f5f1b7a7b5d8 /ui.js
parent8b4d67ddbbb8ea3eb2ad42d7c75a168bf809f33a (diff)
Escape to stop playing current track
E.g. queue whatever album you want to play, press escape to stop playing
the current track, press 2 to focus the queue, S to shuffle, then play
the first track. (If you don't stop the current track first, that track
won't be shuffled with the rest.)
Diffstat (limited to 'ui.js')
-rw-r--r--ui.js10
1 files changed, 10 insertions, 0 deletions
diff --git a/ui.js b/ui.js
index 6e7aad1..7a524ee 100644
--- a/ui.js
+++ b/ui.js
@@ -135,6 +135,8 @@ class AppElement extends FocusElement {
       this.seekBack(10)
     } else if (telc.isCaselessLetter(keyBuf, 'p') || telc.isCaselessLetter(keyBuf, 'k')) {
       this.togglePause()
+    } else if (telc.isEscape(keyBuf)) {
+      this.clearPlayingTrack()
     } else if (telc.isShiftUp(keyBuf)) {
       this.playPreviousTrack(this.playingTrack)
     } else if (telc.isShiftDown(keyBuf)) {
@@ -190,6 +192,13 @@ class AppElement extends FocusElement {
     this.player.togglePause()
   }
 
+  stopPlaying() {
+    // We emit this so playTrack doesn't immediately start a new track.
+    // We aren't *actually* about to play a new track.
+    this.emit('playing new track')
+    this.player.kill()
+  }
+
   async queueGrouplikeItem(topItem, play = true, afterItem = null) {
     const newTrackIndex = this.queueGrouplike.items.length
 
@@ -367,6 +376,7 @@ class AppElement extends FocusElement {
 
   clearPlayingTrack() {
     this.playingTrack = null
+    this.stopPlaying()
     this.playbackInfoElement.clearInfo()
   }
 }