Class: WaitingOnRails::Player
- Inherits:
-
Object
- Object
- WaitingOnRails::Player
- Defined in:
- lib/waiting_on_rails/player.rb
Instance Attribute Summary collapse
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
Instance Method Summary collapse
-
#initialize(music_path) ⇒ Player
constructor
A new instance of Player.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(music_path) ⇒ Player
Returns a new instance of Player.
5 6 7 |
# File 'lib/waiting_on_rails/player.rb', line 5 def initialize(music_path) @music_path = full_path(music_path) end |
Instance Attribute Details
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
3 4 5 |
# File 'lib/waiting_on_rails/player.rb', line 3 def pid @pid end |
Instance Method Details
#start ⇒ Object
9 10 11 |
# File 'lib/waiting_on_rails/player.rb', line 9 def start @pid = spawn("mplayer #{@music_path}", :out => '/dev/null', :err => '/dev/null') end |
#stop ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/waiting_on_rails/player.rb', line 13 def stop return true if @pid.nil? Process.kill(15, @pid) Process.wait(@pid) true rescue Errno::ESRCH, Errno::ECHILD false end |