Sha256: b143af2022052ab4f4fb08937c116f89bbacbb787648326a48c142e1d4456b9c

Contents?: true

Size: 736 Bytes

Versions: 2

Compression:

Stored size: 736 Bytes

Contents

require 'open3'

class Mpg321
  attr_reader :volume

  def initialize
    @volume = 50
    @mus, _stdout, _stderr, _thread = Open3.popen3("mpg321 -R mpg321_ruby")
    Thread.new { loop do _stderr.readline end }
    Thread.new { loop do _stdout.readline end }
    set_volume
  end

  def pause
    @mus.puts "P"
  end

  def stop
    @mus.puts "S"
  end

  def play song_list
    songs = song_list.respond_to?(:join) ? song_list.join(' ') : song_list
    @mus.puts "L #{songs}"
  end

  def volume_up num
    @volume += num
    @volume = [@volume, 100].min
    set_volume
  end

  def volume_down num
    @volume -= num
    @volume = [@volume, 0].max
    set_volume
  end

  private def set_volume
    @mus.puts "G #{@volume}"
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mpg321-0.0.2 lib/mpg321.rb
mpg321-0.0.1 lib/mpg321.rb