Class: Gosu::Sample
- Inherits:
-
Object
- Object
- Gosu::Sample
- Defined in:
- lib/gosu_android/audio/audio.rb
Overview
TODO ManageAudioFocus, when app loses, stop song TODO Raise a warning is the file could not be loaded
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(window, filename) ⇒ Sample
constructor
Constructs a sample that can be played on the specified audio system and loads the sample from a file.
-
#play(volume = 1, speed = 1, looping = false) ⇒ Object
Plays the sample without panning.
-
#play_pan(pan = 0, volume = 1, speed = 1, looping = false) ⇒ Object
TODO Pan is not supported so it is ignored.
Constructor Details
#initialize(window, filename) ⇒ Sample
Constructs a sample that can be played on the specified audio system and loads the sample from a file.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/gosu_android/audio/audio.rb', line 27 def initialize(window, filename) @window = window #Set finalize ObjectSpace.define_finalizer(self, self.class.method(:finalize).to_proc) if not defined? @@pool @@pool = JavaImports::SoundPool.new(MAX_SAMPLES, JavaImports::AudioManager::STREAM_MUSIC, 0) end if(filename.class == Fixnum ) @id = @@pool.load( @window.activity.getApplicationContext, filename, 1 ) else @id = @@pool.load(filename, 1) end end |
Class Method Details
.finalize(id) ⇒ Object
65 66 67 |
# File 'lib/gosu_android/audio/audio.rb', line 65 def Sample.finalize(id) @@pool.unload(@id) end |
Instance Method Details
#play(volume = 1, speed = 1, looping = false) ⇒ Object
Plays the sample without panning. param volume Can be anything from 0.0 (silence) to 1.0 (full volume). param speed Playback speed is only limited by the underlying audio library, and can accept very high or low values. Use 1.0 for normal playback speed.
48 49 50 51 52 53 54 |
# File 'lib/gosu_android/audio/audio.rb', line 48 def play(volume = 1, speed = 1, looping = false) if looping == false @stream_id = @@pool.play(@id, volume, volume, 1, 0, 1.0) else @stream_id = @@pool.play(@id, volume, volume, 1, 1, 1.0) end end |
#play_pan(pan = 0, volume = 1, speed = 1, looping = false) ⇒ Object
TODO Pan is not supported so it is ignored
57 58 59 60 61 62 63 |
# File 'lib/gosu_android/audio/audio.rb', line 57 def play_pan(pan = 0, volume = 1, speed = 1, looping = false) if looping == false @stream_id = @@pool.play(@id, volume, volume, 1, 0, 1.0) else @stream_id = @@pool.play(@id, volume, volume, 1, 1, 1.0) end end |