Class: Rubio::Player
- Inherits:
-
Object
- Object
- Rubio::Player
- Defined in:
- lib/rubio/player.rb
Instance Attribute Summary collapse
-
#backend ⇒ Object
Returns the value of attribute backend.
-
#history ⇒ Object
Returns the value of attribute history.
-
#pid ⇒ Object
Returns the value of attribute pid.
-
#status ⇒ Object
Returns the value of attribute status.
-
#thr ⇒ Object
Returns the value of attribute thr.
Instance Method Summary collapse
- #alive? ⇒ Boolean
-
#initialize(backend = OS.linux? ? 'cvlc' : 'vlc -I rc') ⇒ Player
constructor
A new instance of Player.
- #play(url) ⇒ Object
- #stop ⇒ Object
- #stop? ⇒ Boolean
- #stop_all ⇒ Object
Constructor Details
#initialize(backend = OS.linux? ? 'cvlc' : 'vlc -I rc') ⇒ Player
Returns a new instance of Player.
7 8 9 10 11 12 13 14 15 |
# File 'lib/rubio/player.rb', line 7 def initialize(backend = OS.linux? ? 'cvlc' : 'vlc -I rc') raise unless backend.is_a?(String) @backend = backend @pid = nil @thr = nil @status = [] @history = [] end |
Instance Attribute Details
#backend ⇒ Object
Returns the value of attribute backend.
5 6 7 |
# File 'lib/rubio/player.rb', line 5 def backend @backend end |
#history ⇒ Object
Returns the value of attribute history.
5 6 7 |
# File 'lib/rubio/player.rb', line 5 def history @history end |
#pid ⇒ Object
Returns the value of attribute pid.
5 6 7 |
# File 'lib/rubio/player.rb', line 5 def pid @pid end |
#status ⇒ Object
Returns the value of attribute status.
5 6 7 |
# File 'lib/rubio/player.rb', line 5 def status @status end |
#thr ⇒ Object
Returns the value of attribute thr.
5 6 7 |
# File 'lib/rubio/player.rb', line 5 def thr @thr end |
Instance Method Details
#alive? ⇒ Boolean
17 18 19 20 21 |
# File 'lib/rubio/player.rb', line 17 def alive? return false if @thr.nil? @thr.alive? end |
#play(url) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rubio/player.rb', line 27 def play(url) # Do not include spaces in the command line # if a space exist : # * sh -c command url # this process with @pid will be killed # * cmmand url # will not be killd because pid is differennt # if no space : # * cmmand url # will be killed by @pid raise if url.match(/\s/) @pid = spawn(*backend.split(' '), url) @thr = Process.detach(@pid) @status = [@pid, @thr] @history << @status end |
#stop ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/rubio/player.rb', line 42 def stop return unless alive? r = Process.kill(OS.windows? ? :KILL : :TERM, pid) @thr = nil @pid = nil r end |
#stop? ⇒ Boolean
23 24 25 |
# File 'lib/rubio/player.rb', line 23 def stop? @thr.nil? || @thr.stop? end |
#stop_all ⇒ Object
51 52 53 54 55 |
# File 'lib/rubio/player.rb', line 51 def stop_all @history.each do |pid, thr| Process.kill(OS.windows? ? :KILL : :TERM, pid) if thr.alive? end end |