class Mpg321::Playlist
Constants
- PLAYLIST_ADVANCE_EVENTS
Public Class Methods
new(autoplay = false, client = Client.new)
click to toggle source
# File lib/mpg321/playlist.rb, line 7 def initialize autoplay = false, client = Client.new @tracks = Array.new @access = Mutex.new @autoplay = autoplay @client = client PLAYLIST_ADVANCE_EVENTS.each do |event| @client.on(event) { advance } end end
Public Instance Methods
advance()
click to toggle source
# File lib/mpg321/playlist.rb, line 23 def advance if song = dequeue @client.play song else @client.stop if @client.loaded? end end
each(&block)
click to toggle source
# File lib/mpg321/playlist.rb, line 31 def each &block @access.synchronize { @tracks.each &block } end
enqueue(song)
click to toggle source
# File lib/mpg321/playlist.rb, line 18 def enqueue song @access.synchronize { @tracks << song } advance if @autoplay && !@client.loaded? end
Private Instance Methods
dequeue()
click to toggle source
# File lib/mpg321/playlist.rb, line 37 def dequeue @access.synchronize { @tracks.shift } end