Class: Somadic::Mplayer
- Inherits:
-
Object
- Object
- Somadic::Mplayer
- Includes:
- Observable
- Defined in:
- lib/somadic/mplayer.rb
Constant Summary collapse
- MPLAYER =
'mplayer'
Instance Attribute Summary collapse
-
#cache ⇒ Object
Returns the value of attribute cache.
-
#cache_min ⇒ Object
Returns the value of attribute cache_min.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(options) ⇒ Mplayer
constructor
Sets up a new instance of Mplayer.
-
#start ⇒ Object
Starts mplayer on a new thread.
-
#stop ⇒ Object
Stops mplayer.
- #stopped? ⇒ Boolean
Constructor Details
#initialize(options) ⇒ Mplayer
Sets up a new instance of Mplayer.
Valid options are:
:cache - how much memory in kBytes to use when precaching
a file or URL
:cache_min - playback will start when the cache has been filled up
to `cache_min` of the total.
See the mplayer man page for more.
19 20 21 22 23 24 |
# File 'lib/somadic/mplayer.rb', line 19 def initialize() @url = [:url] @cache = [:cache] @cache_min =[:cache_min] @stopped = true end |
Instance Attribute Details
#cache ⇒ Object
Returns the value of attribute cache.
7 8 9 |
# File 'lib/somadic/mplayer.rb', line 7 def cache @cache end |
#cache_min ⇒ Object
Returns the value of attribute cache_min.
7 8 9 |
# File 'lib/somadic/mplayer.rb', line 7 def cache_min @cache_min end |
#url ⇒ Object
Returns the value of attribute url.
7 8 9 |
# File 'lib/somadic/mplayer.rb', line 7 def url @url end |
Instance Method Details
#start ⇒ Object
Starts mplayer on a new thread.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/somadic/mplayer.rb', line 27 def start @stopped = false @player_thread = Thread.new do cmd = command Somadic::Logger.debug("Mplayer#start: popen #{cmd}") pipe = IO.popen(cmd, 'r+') loop do line = pipe.readline.chomp if line['Starting playback'] Somadic::Logger.debug("Mplayer#pipe: #{line}") elsif line.start_with?('ICY ') begin Somadic::Logger.debug("Mplayer#pipe: #{line}") _, v = line.split(';')[0].split('=') song = v[1..-2] rescue Exception => e Somadic::Logger.debug("unicode fuckup: #{e}") end notify(song) end end pipe.close end rescue => e Somadic::Logger.error("Mplayer#start: error #{e}") end |
#stop ⇒ Object
Stops mplayer.
55 56 57 58 59 |
# File 'lib/somadic/mplayer.rb', line 55 def stop Somadic::Logger.debug("Mplayer#stop") @stopped = true `killall mplayer` end |
#stopped? ⇒ Boolean
61 62 63 |
# File 'lib/somadic/mplayer.rb', line 61 def stopped? @stopped end |