Class: PlayAudio
- Inherits:
-
Object
- Object
- PlayAudio
- Defined in:
- lib/simple_gui_creator/play_audio.rb
Overview
only plays wav/pcm and midi
Constant Summary collapse
- Type =
javax.sound.sampled.LineEvent::Type
Instance Method Summary collapse
-
#initialize(filename) ⇒ PlayAudio
constructor
A new instance of PlayAudio.
- #join_finish ⇒ Object
- #loop ⇒ Object
- #play_till_end ⇒ Object
- #shutdown ⇒ Object
- #start ⇒ Object (also: #play_non_blocking)
- #stop ⇒ Object
- #warmup ⇒ Object
Constructor Details
#initialize(filename) ⇒ PlayAudio
Returns a new instance of PlayAudio.
11 12 13 14 15 |
# File 'lib/simple_gui_creator/play_audio.rb', line 11 def initialize filename raise 'no filename?' unless filename @filename = filename @done = false end |
Instance Method Details
#join_finish ⇒ Object
42 43 44 45 46 |
# File 'lib/simple_gui_creator/play_audio.rb', line 42 def join_finish while !@done sleep 0.01 end end |
#loop ⇒ Object
37 38 39 40 |
# File 'lib/simple_gui_creator/play_audio.rb', line 37 def loop warmup @clip.loop(Clip::LOOP_CONTINUOUSLY) end |
#play_till_end ⇒ Object
48 49 50 51 |
# File 'lib/simple_gui_creator/play_audio.rb', line 48 def play_till_end start join_finish end |
#shutdown ⇒ Object
53 54 55 56 |
# File 'lib/simple_gui_creator/play_audio.rb', line 53 def shutdown @clip.close @audioInputStream.close end |
#start ⇒ Object Also known as: play_non_blocking
30 31 32 33 |
# File 'lib/simple_gui_creator/play_audio.rb', line 30 def start warmup @clip.start end |
#stop ⇒ Object
58 59 60 61 |
# File 'lib/simple_gui_creator/play_audio.rb', line 58 def stop @done = true shutdown end |
#warmup ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/simple_gui_creator/play_audio.rb', line 17 def warmup @audioInputStream = AudioSystem.getAudioInputStream(java.io.File.new @filename) @clip = AudioSystem.getClip @done = false @clip.add_line_listener { |line_event| if (line_event.get_type == Type::STOP || line_event.get_type == Type::CLOSE) @done = true; shutdown end } @clip.open(@audioInputStream) end |