Interface SoundPoolPeer
Low level service provider interface backing com.codename1.gaming.SoundPool.
A peer owns a fixed number of simultaneous playback "voices" and a set of loaded
sounds. Each platform port provides its own peer over the platform's purpose
built low latency audio API (Android SoundPool, iOS AVAudioEngine, the
desktop javax.sound.sampled mixer, WebAudio in the browser). When a port does
not provide one, com.codename1.gaming.SoundPool falls back to
MediaSoundPoolPeer, which is implemented purely on top of the existing
MediaManager.
A loaded sound is represented by an opaque Object handle returned from
#loadSound(String) / #loadSound(InputStream, String). A playing voice is
represented by an int id returned from
#play(Object, float, float, float, int); -1 means no voice was available.
Per voice operations are no-ops if the voice has already finished and been
recycled.
Callbacks from the underlying audio engine may arrive off the Codename One EDT; implementations must keep their own bookkeeping thread safe.
-
Method Summary
Modifier and TypeMethodDescriptionvoidPauses all active playback (for example when the app is sent to the background).voidResumes playback paused by#autoPause().loadSound(InputStream data, String mimeType) Loads a short sound from a stream, decoding/buffering it up front so that playback latency is paid here rather than at#play.Loads a short sound from a uri (for example ajar://resource path).voidpauseVoice(int voiceId) intPlays a loaded sound, returning a voice id or-1if the pool is exhausted.voidrelease()Releases the whole pool and all loaded sounds.voidresumeVoice(int voiceId) voidsetPan(int voiceId, float pan) voidsetRate(int voiceId, float rate) voidsetVolume(int voiceId, float volume) voidstopAll()Stops every currently playing voice.voidstopVoice(int voiceId) voidunloadSound(Object sound) Releases a single loaded sound and its buffers.
-
Method Details
-
loadSound
Loads a short sound from a stream, decoding/buffering it up front so that playback latency is paid here rather than at#play. The stream is fully consumed and closed.- Throws:
IOException
-
loadSound
Loads a short sound from a uri (for example ajar://resource path).- Throws:
IOException
-
play
Plays a loaded sound, returning a voice id or
-1if the pool is exhausted.Parameters
-
sound: a handle returned from one of the load methods -
volume: 0.0 (silent) to 1.0 (full) -
pan: -1.0 (full left) to 1.0 (full right), 0.0 centered -
rate: playback rate / pitch, 1.0 is normal (typically 0.5 to 2.0) -
loop: 0 plays once, -1 loops forever, n repeats n extra times
-
-
setVolume
void setVolume(int voiceId, float volume) -
setRate
void setRate(int voiceId, float rate) -
setPan
void setPan(int voiceId, float pan) -
pauseVoice
void pauseVoice(int voiceId) -
resumeVoice
void resumeVoice(int voiceId) -
stopVoice
void stopVoice(int voiceId) -
stopAll
void stopAll()Stops every currently playing voice. -
autoPause
void autoPause()Pauses all active playback (for example when the app is sent to the background). -
autoResume
void autoResume()Resumes playback paused by#autoPause(). -
unloadSound
Releases a single loaded sound and its buffers. -
release
void release()Releases the whole pool and all loaded sounds.
-