public interface SoundPoolPeer
Known subtypesCompletionAwareSoundPoolPeer
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.
Methods
Method details
loadSound
public abstract Object loadSound(InputStream data, String mimeType)
throws IOException#play. The stream is fully
consumed and closed.Throws
loadSound
public abstract Object loadSound(String uri)
throws IOExceptionjar:// resource path).Throws
play
public abstract int play(Object sound, float volume, float pan, float rate, int loop)-1 if the pool is exhausted.Parameters
soundObject- a handle returned from one of the load methods
volumefloat- 0.0 (silent) to 1.0 (full)
panfloat- -1.0 (full left) to 1.0 (full right), 0.0 centered
ratefloat- playback rate / pitch, 1.0 is normal (typically 0.5 to 2.0)
loopint- 0 plays once, -1 loops forever, n repeats n extra times
setVolume
public abstract void setVolume(int voiceId, float volume)setRate
public abstract void setRate(int voiceId, float rate)setPan
public abstract void setPan(int voiceId, float pan)pauseVoice
public abstract void pauseVoice(int voiceId)resumeVoice
public abstract void resumeVoice(int voiceId)stopVoice
public abstract void stopVoice(int voiceId)stopAll
public abstract void stopAll()autoPause
public abstract void autoPause()autoResume
public abstract void autoResume()#autoPause().unloadSound
public abstract void unloadSound(Object sound)release
public abstract void release()