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

#initializeMpgWrapperPlayer

Returns a new instance of MpgWrapperPlayer.



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 19

def initialize
   @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

Returns:

  • (Boolean)


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

def can_http?; true; end

#forward(seconds = 2) ⇒ Object



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

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

#lengthObject



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

def length;   @seconds_total   end

#pauseObject



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

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

#paused?Boolean

Returns:

  • (Boolean)


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

def paused?;  @state == STATE_PAUSED  end

#play(file = nil) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 34

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)


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

def playing?; @state == STATE_PLAYING end

#positionObject



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

def position; @seconds_played  end

#position_percentObject



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

def position_percent
   @seconds_played.to_f / length rescue 0.0
end

#rewind(seconds = 2) ⇒ Object Also known as: backward



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

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

#seek(seconds) ⇒ Object



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

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

#statusObject



58
59
60
61
62
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 58

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

#stopObject



45
46
47
48
49
50
51
52
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 45

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)


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

def stopped?; @state == STATE_STOPPED end

#toggleObject



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

def toggle; write(?P)                            end

#use_polling(interval) ⇒ Object



82
83
84
85
# File 'lib/ektoplayer/players/mpg_wrapper_player.rb', line 82

def use_polling(interval)
   @polling_interval = interval
   start_polling_thread
end