Class: AudioPlayer

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

Constant Summary collapse

@@mciSendString =
Win32API.new("winmm", "mciSendString", "PPLL", "L")

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ AudioPlayer

Returns a new instance of AudioPlayer.



13
14
15
16
17
18
19
# File 'lib/audio_player.rb', line 13

def initialize(file)
	@instance_name = "rb_" + generate_random_string(4)

	send "open #{file} alias #{@instance_name}"

	self.volume = 500
end

Instance Method Details

#playObject



25
26
27
# File 'lib/audio_player.rb', line 25

def play
	send "play #{@instance_name}"
end

#send(str) ⇒ Object



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

def send(str)
	@@mciSendString.call str, "", 0, 0
end

#stopObject



28
29
30
# File 'lib/audio_player.rb', line 28

def stop
	send "stop #{@instance_name}"
end

#volumeObject



36
37
38
# File 'lib/audio_player.rb', line 36

def volume
	@volume
end

#volume=(v) ⇒ Object



32
33
34
35
# File 'lib/audio_player.rb', line 32

def volume=(v)
	send "setaudio #{@instance_name} volume to #{v}"
	@volume = v 
end