Class: MusicBlender::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/music_blender/player.rb

Constant Summary collapse

PLAYING_STATUS_CODE_MAP =
{
  -1 => 'Started',
  0 => 'Stopped',
  1 => 'Paused',
  2 => 'Resumed',
}
METHODS_DELEGATED_TO_MONITOR =
[
  :frames,
  :frames_remaining,
  :playing,
  :seconds,
  :seconds_remaining,
  :song_name,
  :stop_pause_status
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePlayer

Returns a new instance of Player.



29
30
31
32
33
34
# File 'lib/music_blender/player.rb', line 29

def initialize
  @stdin, @stdout, @stderr, @wait_thread =
    Open3.popen3('mpg123 --rva-mix -R')
  @logger = Logger.new("#{BLENDER_ROOT}/log/player.log", 10, 1024000)
  Thread.new { monitor.run }
end

Instance Attribute Details

#current_trackObject (readonly)

Returns the value of attribute current_track.



21
22
23
# File 'lib/music_blender/player.rb', line 21

def current_track
  @current_track
end

#loggerObject (readonly)

Returns the value of attribute logger.



21
22
23
# File 'lib/music_blender/player.rb', line 21

def logger
  @logger
end

#stderrObject (readonly)

Returns the value of attribute stderr.



21
22
23
# File 'lib/music_blender/player.rb', line 21

def stderr
  @stderr
end

#stdinObject (readonly)

Returns the value of attribute stdin.



21
22
23
# File 'lib/music_blender/player.rb', line 21

def stdin
  @stdin
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



21
22
23
# File 'lib/music_blender/player.rb', line 21

def stdout
  @stdout
end

Instance Method Details

#pauseObject



41
42
43
# File 'lib/music_blender/player.rb', line 41

def pause
  stdin.puts 'PAUSE'
end

#playObject



36
37
38
39
# File 'lib/music_blender/player.rb', line 36

def play
  set_current_track_last_played_at
  stdin.puts "LOAD #{pick_a_track.full_path}"
end

#quitObject



49
50
51
# File 'lib/music_blender/player.rb', line 49

def quit
  stdin.puts 'QUIT'
end

#status_stringObject



53
54
55
# File 'lib/music_blender/player.rb', line 53

def status_string
  PLAYING_STATUS_CODE_MAP[stop_pause_status]
end

#stopObject



45
46
47
# File 'lib/music_blender/player.rb', line 45

def stop
  stdin.puts 'STOP'
end