about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-10-09 06:49:56 +0000
committerEric Wong <normalperson@yhbt.net>2013-10-09 06:50:10 +0000
commit0eec3250509c290d7be0cec43b06cb621f2b71f8 (patch)
tree5814d2ec5dd0c490a09125eae6766ce493a39f9e /lib
parentd131bb0964ba323eac225c888a84875c1ae8cd3d (diff)
downloaddtas-0eec3250509c290d7be0cec43b06cb621f2b71f8.tar.gz
We should not have the position point too far past the end of the
list.  This allows playback to start when we do "tl add" on
an idle player after removing something from the tracklist.
Diffstat (limited to 'lib')
-rw-r--r--lib/dtas/tracklist.rb12
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/dtas/tracklist.rb b/lib/dtas/tracklist.rb
index 6856648..325db20 100644
--- a/lib/dtas/tracklist.rb
+++ b/lib/dtas/tracklist.rb
@@ -101,11 +101,15 @@ class DTAS::Tracklist # :nodoc:
 
   def remove_track(track_id)
     by_track_id = _track_id_map
-    if idx = by_track_id.delete(track_id)
-      @list[idx] = nil
-      @list.compact!
-      # TODO: what do we do with @pos (and the currently-playing track)
+    idx = by_track_id.delete(track_id) or return false
+    @list[idx] = nil
+    @list.compact!
+    len = @list.size
+    if @pos >= len
+      @pos = len == 0 ? TL_DEFAULTS["pos"] : len
     end
+    @goto_pos = @goto_pos = nil # TODO: reposition?
+    true
   end
 
   def go_to(track_id, offset_hhmmss = nil)