class Somadic::BaseChannel
Constants
- API_TIMEOUT
- ONE_DAY
Attributes
channels[R]
song[R]
Public Class Methods
new(options)
click to toggle source
# File lib/somadic/base_channel.rb, line 8 def initialize(options) @url = options[:url] playlist = @url.split('/').last if playlist.end_with?('.pls') name = playlist[0..playlist.index('.pls') - 1] elsif playlist.end_with?('.m3u') name = playlist[0..playlist.index('.m3u') - 1] else Somadic::Logger.error("BaseChannel#initialize: bad playlist #{playlist}") return end @channel = find_channel(name) @mp = Mplayer.new(options) @mp.add_observer(self) @listeners = options[:listeners] end
Public Instance Methods
channel_list()
click to toggle source
# File lib/somadic/base_channel.rb, line 60 def channel_list @channels end
find_channel(name)
click to toggle source
# File lib/somadic/base_channel.rb, line 56 def find_channel(name) raise NotImplementedError end
start()
click to toggle source
Let's go already.
# File lib/somadic/base_channel.rb, line 27 def start Somadic::Logger.debug('BaseChannel#start') @mp.start rescue => e Somadic::Logger.error("BaseChannel#start error: #{e}") end
stop()
click to toggle source
Enough already.
# File lib/somadic/base_channel.rb, line 35 def stop Somadic::Logger.debug('BaseChannel#stop') @mp.stop end
stopped?()
click to toggle source
# File lib/somadic/base_channel.rb, line 40 def stopped? @mp.stopped? end
update(time, song)
click to toggle source
Observer callback, and also one of the simplest displays possible.
# File lib/somadic/base_channel.rb, line 45 def update(time, song) Somadic::Logger.debug("BaseChannel#update: #{time} - #{song}") songs = [{ 'started' => Time.now.to_i - 1, 'duration' => 1, 'track' => song, 'votes' => { 'up' => 0, 'down' => 0 } }] @listeners.each do |l| l.update(@channel, songs) if l.respond_to?(:update) end end