Class: AudioPlayer
- Inherits:
-
Object
- Object
- AudioPlayer
- Defined in:
- lib/audio_player.rb
Constant Summary collapse
- @@mciSendString =
Win32API.new("winmm", "mciSendString", "PPLL", "L")
Instance Method Summary collapse
-
#initialize(file) ⇒ AudioPlayer
constructor
A new instance of AudioPlayer.
- #play ⇒ Object
- #send(str) ⇒ Object
- #stop ⇒ Object
- #volume ⇒ Object
- #volume=(v) ⇒ Object
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
#play ⇒ Object
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 |
#stop ⇒ Object
28 29 30 |
# File 'lib/audio_player.rb', line 28 def stop send "stop #{@instance_name}" end |
#volume ⇒ Object
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 |