Class: PlayAudio
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(filename) ⇒ PlayAudio
constructor
A new instance of PlayAudio.
-
#loop ⇒ Object
will fail is stream > 1 MB.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(filename) ⇒ PlayAudio
Returns a new instance of PlayAudio.
25 26 27 |
# File 'lib/play_audio.rb', line 25 def initialize filename @filename = filename end |
Class Method Details
.loop(filename) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/play_audio.rb', line 16 def self.loop filename i = java.io.FileInputStream.new(filename) a = AudioStream.new(i) b = a.get_data # failing means too big of data... c = ContinuousAudioDataStream.new(b) AudioPlayer.player.start(c) c end |
.play(filename) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/play_audio.rb', line 9 def self.play filename i = java.io.FileInputStream.new(filename) a = AudioStream.new(i) AudioPlayer.player.start(a) a end |
Instance Method Details
#loop ⇒ Object
will fail is stream > 1 MB
34 35 36 37 |
# File 'lib/play_audio.rb', line 34 def loop # will fail is stream > 1 MB raise if @audio_stream @audio_stream = PlayAudio.loop @filename end |
#start ⇒ Object
29 30 31 32 |
# File 'lib/play_audio.rb', line 29 def start raise if @audio_stream @audio_stream = PlayAudio.play @filename end |
#stop ⇒ Object
39 40 41 42 43 |
# File 'lib/play_audio.rb', line 39 def stop raise unless @audio_stream AudioPlayer.player.stop(@audio_stream) @audio_stream = nil end |