Class: MultimediaParadise::Rubio::Model::Player
- Inherits:
-
Object
- Object
- MultimediaParadise::Rubio::Model::Player
- Defined in:
- lib/multimedia_paradise/gui/glimmer/rubio/model/player.rb
Overview
Rubio::Model::Player
Constant Summary collapse
- CURRENTLY_PLAYING_NONE =
'None'
- CURRENTLY_PLAYING_LENGTH_PER_LINE =
90
- USE_THIS_PLAYER =
#
USE_THIS_PLAYER
#
'mpv'
Instance Attribute Summary collapse
-
#backend ⇒ Object
or vlc.
-
#currently_playing ⇒ Object
Returns the value of attribute currently_playing.
-
#history ⇒ Object
Returns the value of attribute history.
-
#pid ⇒ Object
Returns the value of attribute pid.
-
#show_currently_playing ⇒ Object
(also: #show_currently_playing?)
readonly
Returns the value of attribute show_currently_playing.
-
#status ⇒ Object
Returns the value of attribute status.
-
#thr ⇒ Object
Returns the value of attribute thr.
Instance Method Summary collapse
-
#alive? ⇒ Boolean
# === alive? ========================================================================= #.
-
#continuously_fetch_currently_playing ⇒ Object
# === continuously_fetch_currently_playing ========================================================================= #.
-
#currently_playing_text(currently_playing_info = info) ⇒ Object
# === currently_playing_text ========================================================================= #.
-
#info ⇒ Object
# === info.
-
#initialize(backend = USE_THIS_PLAYER, show_currently_playing: true) ⇒ Player
constructor
# === initialize ========================================================================= #.
-
#play(url, station_name: 'N/A') ⇒ Object
# === play ========================================================================= #.
-
#reset ⇒ Object
# === reset ========================================================================= #.
-
#stop(thr: nil, pid: nil, io: nil) ⇒ Object
# === stop ========================================================================= #.
-
#stop? ⇒ Boolean
# === stop? ========================================================================= #.
-
#stop_all ⇒ Object
# === stop_all ========================================================================= #.
-
#update_currently_playing ⇒ Object
# === update_currently_playing ========================================================================= #.
Constructor Details
#initialize(backend = USE_THIS_PLAYER, show_currently_playing: true) ⇒ Player
#
initialize
#
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/player.rb', line 33 def initialize( backend = USE_THIS_PLAYER, #+' -I rc', show_currently_playing: true ) raise unless backend.is_a?(String) reset @backend = backend @show_currently_playing = self. = CURRENTLY_PLAYING_NONE end |
Instance Attribute Details
#backend ⇒ Object
or vlc
21 22 23 |
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/player.rb', line 21 def backend @backend end |
#currently_playing ⇒ Object
Returns the value of attribute currently_playing.
27 28 29 |
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/player.rb', line 27 def @currently_playing end |
#history ⇒ Object
Returns the value of attribute history.
25 26 27 |
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/player.rb', line 25 def history @history end |
#pid ⇒ Object
Returns the value of attribute pid.
22 23 24 |
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/player.rb', line 22 def pid @pid end |
#show_currently_playing ⇒ Object (readonly) Also known as: show_currently_playing?
Returns the value of attribute show_currently_playing.
26 27 28 |
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/player.rb', line 26 def @show_currently_playing end |
#status ⇒ Object
Returns the value of attribute status.
24 25 26 |
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/player.rb', line 24 def status @status end |
#thr ⇒ Object
Returns the value of attribute thr.
23 24 25 |
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/player.rb', line 23 def thr @thr end |
Instance Method Details
#alive? ⇒ Boolean
#
alive?
#
68 69 70 |
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/player.rb', line 68 def alive? @thr&.alive? || (@io && !@io.closed?) end |
#continuously_fetch_currently_playing ⇒ Object
#
continuously_fetch_currently_playing
#
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/player.rb', line 109 def return if @continuously_fetching_currently_playing @continuously_fetching_currently_playing = true Glimmer::LibUI.timer(1) { @continuously_fetching_currently_playing } end |
#currently_playing_text(currently_playing_info = info) ⇒ Object
#
currently_playing_text
#
132 133 134 135 136 137 138 139 140 |
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/player.rb', line 132 def ( = info ) if && !.strip.empty? [@playing_station_name, ].join(' - ') else @playing_station_name end end |
#info ⇒ Object
#
info
Run “info”.
#
147 148 149 150 151 152 153 154 155 |
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/player.rb', line 147 def info result = io_command('info') = result.lines.find {|l| l.include?('now_playing:')} if .split('now_playing:').last.chomp.strip end rescue nil end |
#play(url, station_name: 'N/A') ⇒ Object
#
play
#
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/player.rb', line 82 def play(url, station_name: 'N/A') # 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/) @playing_station_name = station_name if && backend.include?(USE_THIS_PLAYER) && !OS.windows? @io = IO.popen("#{backend} \"#{url}\"", 'r+') else @pid = spawn(*backend.split(' '), url) @thr = Process.detach(@pid) end @status = { thr: @thr, pid: @pid, io: @io } @history << @status end |
#reset ⇒ Object
#
reset
#
47 48 49 50 51 52 53 54 55 |
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/player.rb', line 47 def reset # ======================================================================= # # === @pid # ======================================================================= # @pid = nil @thr = nil @status = {} @history = [] end |
#stop(thr: nil, pid: nil, io: nil) ⇒ Object
#
stop
#
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/player.rb', line 160 def stop(thr: nil, pid: nil, io: nil) thr ||= @thr pid ||= @pid io ||= @io if thr and thr.alive? result = Process.kill(OS.windows? ? :KILL : :TERM, pid) elsif io && !io.closed? io.close result = io.closed? self. = CURRENTLY_PLAYING_NONE end thr = nil pid = nil io = nil return result end |
#stop? ⇒ Boolean
#
stop?
#
75 76 77 |
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/player.rb', line 75 def stop? @thr.nil? || @thr.stop? end |
#stop_all ⇒ Object
#
stop_all
#
180 181 182 183 |
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/player.rb', line 180 def stop_all @continuously_fetching_currently_playing = false @history.each { |history| stop(**history) } end |
#update_currently_playing ⇒ Object
#
update_currently_playing
#
123 124 125 126 127 |
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/player.rb', line 123 def Glimmer::LibUI.queue_main { self. = if alive? } end |