Class: MpgWrapperPlayer

Inherits:
Object
  • Object
show all
Defined in:
lib/ektoplayer/players/mpg_wrapper_player.rb

Constant Summary collapse

CMD_FORMAT =
'FORMAT'.freeze
CMD_SAMPLE =
'SAMPLE'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(audio_system) ⇒ MpgWrapperPlayer

Returns a new instance of MpgWrapperPlayer.

[View source]

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

#eventsObject (readonly)

Returns the value of attribute events.


13
14
15
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 13

def events
  @events
end

#fileObject (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.

Returns:

  • (Boolean)
[View source]

37
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 37

def can_http?; false; end

#forward(seconds = 2) ⇒ Object

[View source]

78
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 78

def forward(seconds = 2) write("J +#{seconds}s") end

#lengthObject

[View source]

70
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 70

def length;   @seconds_total   end

#pauseObject

[View source]

47
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 47

def pause;  write(?P) if @state == STATE_PLAYING end

#paused?Boolean

Returns:

  • (Boolean)
[View source]

59
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 59

def paused?;  @state == STATE_PAUSED  end

#play(file = nil) ⇒ Object

[View source]

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

Returns:

  • (Boolean)
[View source]

61
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 61

def playing?; @state == STATE_PLAYING end

#positionObject

[View source]

69
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 69

def position; @seconds_played  end

#position_percentObject

[View source]

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

[View source]

77
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 77

def rewind(seconds = 2)  write("J -#{seconds}s") end

#seek(seconds) ⇒ Object

[View source]

76
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 76

def seek(seconds)        write("J  #{seconds}s") end

#statusObject

[View source]

63
64
65
66
67
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 63

def status
   return :playing if playing?
   return :paused  if paused?
   return :stopped if stopped?
end

#stopObject

[View source]

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

Returns:

  • (Boolean)
[View source]

60
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 60

def stopped?; @state == STATE_STOPPED end

#toggleObject

[View source]

48
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 48

def toggle; write(?P)                            end

#use_polling(interval) ⇒ Object

[View source]

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