Class: Sound

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#clipObject

Returns the value of attribute clip.



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

def clip
  @clip
end

Class Method Details

.load_sound(file_name) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/releaseable/sound.rb', line 23

def self.load_sound(file_name)
  sound = new

  url = java.net.URL.new("file://" + ASSETS_DIR + file_name) # nasty little hack due to borked get_resource (means applet won't be easy..)
  ais = AudioSystem.get_audio_input_stream(url)
  info = DataLine::Info.new(Clip.java_class, ais.format)
  clip = AudioSystem.get_line(info)
  clip.open(ais)
  clip.extend JRuby::Synchronized
  sound.clip = clip

  sound
end

Instance Method Details

#playObject



37
38
39
40
41
42
43
44
45
# File 'lib/releaseable/sound.rb', line 37

def play
  if clip
    Thread.new do
      clip.stop
      clip.frame_position = 0
      clip.start
    end
  end
end