Class: Ruby2D::Audio

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby2d/audio.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, loop: false) ⇒ Audio

Create an audio object from a file

Raises:



6
7
8
9
10
11
12
# File 'lib/ruby2d/audio.rb', line 6

def initialize(path, loop: false)
  @path = path.to_s
  raise Error, "Cannot find audio file `#{@path}`" unless File.exist? @path

  @loop = loop ? true : false
  @ext_audio = Ext.audio_load(@path)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/ruby2d/audio.rb', line 3

def path
  @path
end

Class Method Details

.volumeObject

Get the mixer volume, 0.0 to 1.0



62
63
64
# File 'lib/ruby2d/audio.rb', line 62

def volume
  Ext.audio_get_mixer_volume
end

.volume=(volume) ⇒ Object

Set the mixer volume, 0.0 to 1.0



67
68
69
# File 'lib/ruby2d/audio.rb', line 67

def volume=(volume)
  Ext.audio_set_mixer_volume(volume.clamp(0.0, 1.0))
end

Instance Method Details

#lengthObject

Returns the length in seconds



46
47
48
# File 'lib/ruby2d/audio.rb', line 46

def length
  Ext.audio_length(@ext_audio)
end

#loop=(value) ⇒ Object

Set looping



40
41
42
43
# File 'lib/ruby2d/audio.rb', line 40

def loop=(value)
  @loop = value ? true : false
  Ext.audio_set_loop(@ext_audio, @loop)
end

#looping?Boolean

Whether the audio loops on play

Returns:

  • (Boolean)


35
36
37
# File 'lib/ruby2d/audio.rb', line 35

def looping?
  @loop
end

#pauseObject

Pause the music



20
21
22
# File 'lib/ruby2d/audio.rb', line 20

def pause
  Ext.audio_pause(@ext_audio)
end

#playObject

Play the sound



15
16
17
# File 'lib/ruby2d/audio.rb', line 15

def play
  Ext.audio_play(@ext_audio, @loop)
end

#resumeObject

Resume paused music



25
26
27
# File 'lib/ruby2d/audio.rb', line 25

def resume
  Ext.audio_resume(@ext_audio)
end

#stop(ms_fade = 0) ⇒ Object

Stop the sound



30
31
32
# File 'lib/ruby2d/audio.rb', line 30

def stop(ms_fade = 0)
  Ext.audio_stop(@ext_audio, ms_fade)
end

#volumeObject

Get the volume of the sound, 0.0 to 1.0



51
52
53
# File 'lib/ruby2d/audio.rb', line 51

def volume
  Ext.audio_get_volume(@ext_audio)
end

#volume=(volume) ⇒ Object

Set the volume of the sound, 0.0 to 1.0



56
57
58
# File 'lib/ruby2d/audio.rb', line 56

def volume=(volume)
  Ext.audio_set_volume(@ext_audio, volume.clamp(0.0, 1.0))
end