Browse files

Check to see if the play list is empty first.

  • Loading branch information...
1 parent 5028c59 commit 283dbc461a659a28028205e55a8813a74c14fd61 @njh committed Apr 26, 2008
Showing with 26 additions and 14 deletions.
  1. +26 −14 examples/tracklist.rb
View
40 examples/tracklist.rb
@@ -1,6 +1,10 @@
#!/usr/bin/ruby
#
-# Copyright (C) 2008 by Nicholas J Humfrey
+# Script to display the URI, artist and title for the tracks on the tracklist.
+#
+# Author:: Nicholas J Humfrey (mailto:njh@aelius.com)
+# Copyright:: Copyright (c) 2008 Nicholas J Humfrey
+# License:: Distributes under the same terms as Ruby
#
$:.unshift File.dirname(__FILE__)+'/../lib'
@@ -11,20 +15,28 @@
# Get the number of tracks on the tracklist
len = mpris.tracklist.length
-current = mpris.tracklist.current_track
+if (len <= 0)
+ puts "There are no tracks on the tracklist."
-i=0
-while (i<len) do
+else
- # Print asterisk next to currently playing track
- if (i==current)
- print "* "
- else
- print " "
- end
+ # Get the number of the currently playing track
+ current = mpris.tracklist.current_track
+
+ i=0
+ while (i<len) do
- # There is a bug in VLC, which makes tracklist start at 1
- meta = mpris.tracklist.metadata(i+1)
- puts "#{i}: #{meta['URI']} (#{meta['artist']} - #{meta['title']})"
- i+=1
+ # Print asterisk next to currently playing track
+ if (i==current)
+ print "* "
+ else
+ print " "
+ end
+
+ # There is a bug in VLC, which makes tracklist start at 1
+ meta = mpris.tracklist.metadata(i+1)
+ puts "#{i}: #{meta['URI']} (#{meta['artist']} - #{meta['title']})"
+ i+=1
+ end
+
end

0 comments on commit 283dbc4

Please sign in to comment.