Class: Mumble::AudioPlayer

Inherits:
Object
  • Object
show all
Includes:
ThreadTools
Defined in:
lib/mumble-ruby/audio_player.rb

Constant Summary collapse

COMPRESSED_SIZE =
960

Instance Method Summary collapse

Constructor Details

#initialize(type, connection, sample_rate, bitrate) ⇒ AudioPlayer

Returns a new instance of AudioPlayer.



8
9
10
11
12
13
14
15
16
# File 'lib/mumble-ruby/audio_player.rb', line 8

def initialize(type, connection, sample_rate, bitrate)
  @packet_header = (type << 5).chr
  @conn = connection
  @pds = PacketDataStream.new
  @queue = Queue.new
  @wav_format = WaveFile::Format.new :mono, :pcm_16, sample_rate

  create_encoder sample_rate, bitrate
end

Instance Method Details

#play_file(file) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/mumble-ruby/audio_player.rb', line 30

def play_file(file)
  unless playing?
    @file = WaveFile::Reader.new(file, @wav_format)
    Thread.new { bounded_produce }
    @playing = true
  end
end

#playing?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/mumble-ruby/audio_player.rb', line 26

def playing?
  @playing ||= false
end

#stopObject



46
47
48
49
50
51
52
53
# File 'lib/mumble-ruby/audio_player.rb', line 46

def stop
  if playing?
    kill_threads
    @encoder.reset
    @file.close unless @file.closed?
    @playing = false
  end
end

#stream_named_pipe(pipe) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/mumble-ruby/audio_player.rb', line 38

def stream_named_pipe(pipe)
  unless playing?
    @file = File.open(pipe, 'rb')
    spawn_threads :produce, :consume
    @playing = true
  end
end

#volumeObject



18
19
20
# File 'lib/mumble-ruby/audio_player.rb', line 18

def volume
  @volume ||= 100
end

#volume=(volume) ⇒ Object



22
23
24
# File 'lib/mumble-ruby/audio_player.rb', line 22

def volume=(volume)
  @volume = volume
end