Class: MpgWrapperPlayer
- Inherits:
-
Object
- Object
- MpgWrapperPlayer
- Defined in:
- lib/ektoplayer/players/mpg_wrapper_player.rb
Constant Summary collapse
- CMD_FORMAT =
'FORMAT'.freeze
- CMD_SAMPLE =
'SAMPLE'.freeze
Instance Attribute Summary collapse
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Instance Method Summary collapse
-
#can_http? ⇒ Boolean
NOTE Since ektoplazm.com switched to Cloudflare (using HTTP/2.0) mpg123 cannot handle those streams anymore.
- #forward(seconds = 2) ⇒ Object
-
#initialize(audio_system) ⇒ MpgWrapperPlayer
constructor
A new instance of MpgWrapperPlayer.
- #length ⇒ Object
- #pause ⇒ Object
- #paused? ⇒ Boolean
- #play(file = nil) ⇒ Object
- #playing? ⇒ Boolean
- #position ⇒ Object
- #position_percent ⇒ Object
- #rewind(seconds = 2) ⇒ Object (also: #backward)
- #seek(seconds) ⇒ Object
- #status ⇒ Object
- #stop ⇒ Object
- #stopped? ⇒ Boolean
- #toggle ⇒ Object
- #use_polling(interval) ⇒ Object
Constructor Details
#initialize(audio_system) ⇒ MpgWrapperPlayer
Returns a new instance of MpgWrapperPlayer.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 19 def initialize(audio_system) @audio_system = audio_system @events = Events.new(:play, :pause, :stop, :position_change) @lock = Mutex.new @mpg123_in, @mpg123_out, @mpg123_thread = nil, nil, nil @state = 0 @file = '' @polling_interval = 0.9 @seconds_played = @seconds_total = 0 @track_completed = nil end |
Instance Attribute Details
#events ⇒ Object (readonly)
Returns the value of attribute events.
13 14 15 |
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 13 def events @events end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
13 14 15 |
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 13 def file @file end |
Instance Method Details
#can_http? ⇒ Boolean
NOTE Since ektoplazm.com switched to Cloudflare (using HTTP/2.0) mpg123 cannot handle those streams anymore. This may change in future versions of mpg123.
37 |
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 37 def can_http?; false; end |
#forward(seconds = 2) ⇒ Object
78 |
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 78 def forward(seconds = 2) write("J +#{seconds}s") end |
#length ⇒ Object
70 |
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 70 def length; @seconds_total end |
#pause ⇒ Object
47 |
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 47 def pause; write(?P) if @state == STATE_PLAYING end |
#paused? ⇒ Boolean
59 |
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 59 def paused?; @state == STATE_PAUSED end |
#play(file = nil) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 39 def play(file=nil) start_mpg123_thread @track_completed = :track_completed @file = file if file write("L #{@file}") Thread.new { sleep 3; write(CMD_FORMAT) } end |
#playing? ⇒ Boolean
61 |
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 61 def ; @state == STATE_PLAYING end |
#position ⇒ Object
69 |
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 69 def position; @seconds_played end |
#position_percent ⇒ Object
72 73 74 |
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 72 def position_percent @seconds_played.to_f / length rescue 0.0 end |
#rewind(seconds = 2) ⇒ Object Also known as: backward
77 |
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 77 def rewind(seconds = 2) write("J -#{seconds}s") end |
#seek(seconds) ⇒ Object
76 |
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 76 def seek(seconds) write("J #{seconds}s") end |
#status ⇒ Object
63 64 65 66 67 |
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 63 def status return :playing if return :paused if paused? return :stopped if stopped? end |
#stop ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 50 def stop stop_polling_thread @track_completed = nil @seconds_played = @seconds_total = 0 @events.trigger(:position_change) @events.trigger(:stop) write(?Q) if @state != STATE_STOPPED end |
#stopped? ⇒ Boolean
60 |
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 60 def stopped?; @state == STATE_STOPPED end |
#toggle ⇒ Object
48 |
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 48 def toggle; write(?P) end |
#use_polling(interval) ⇒ Object
87 88 89 90 |
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 87 def use_polling(interval) @polling_interval = interval start_polling_thread end |