Class: PlayMp3Audio

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

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ PlayMp3Audio

does not work with .wav, unfortunately…



9
10
11
# File 'lib/simple_gui_creator/play_mp3_audio.rb', line 9

def initialize filename # does not work with .wav, unfortunately...
  @filename = filename
end

Instance Method Details

#joinObject



23
24
25
# File 'lib/simple_gui_creator/play_mp3_audio.rb', line 23

def join
  @thread.join
end

#play_till_endObject



27
28
29
30
# File 'lib/simple_gui_creator/play_mp3_audio.rb', line 27

def play_till_end
  start
	 join
end

#startObject Also known as: play_non_blocking



13
14
15
16
17
18
19
20
21
# File 'lib/simple_gui_creator/play_mp3_audio.rb', line 13

def start
   raise 'file not found?' unless File.exist? @filename
   fis     = java.io.FileInputStream.new(@filename)
   bstream = java.io.BufferedInputStream.new(fis)
   @player = Player.new(bstream)
@thread = Thread.new { 
  @player.play 
}				
end

#stopObject



34
35
36
37
38
39
40
# File 'lib/simple_gui_creator/play_mp3_audio.rb', line 34

def stop
  if @player
    @player.close # at least they give us this method yikes
 @player = nil
	 end
	 # raising here means you didn't call 
end