android :: SoundPool :: defaultinit
android :: SoundPool :: left_volume=
Left volume value, range 0.0 to 1.0android :: SoundPool :: load_name
Load a sound by itsname
in the resources, the sound must be in the res/raw
folder
android :: SoundPool :: max_streams
The maximum number of simultaneous streams for this SoundPoolandroid :: SoundPool :: max_streams=
The maximum number of simultaneous streams for this SoundPoolandroid :: SoundPool :: right_volume=
Right volume value, range 0.0 to 1.0android :: SoundPool :: src_quality
The sample-rate converter quality, currently has no effectandroid :: SoundPool :: src_quality=
The sample-rate converter quality, currently has no effectandroid :: SoundPool :: stream_loop=
Set loop mode on a streamandroid :: SoundPool :: stream_priority=
Change stream priorityandroid :: SoundPool :: stream_rate=
Change playback rateandroid :: SoundPool :: stream_type
The audio stream type, 3 is STREAM_MUSIC, default for game applicationandroid :: SoundPool :: stream_type=
The audio stream type, 3 is STREAM_MUSIC, default for game applicationandroid :: SoundPool :: stream_volume
Set stream volumecore :: Object :: class_factory
Implementation used byget_class
to create the specific class.
android :: SoundPool :: defaultinit
core :: Object :: defaultinit
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
android :: SoundPool :: left_volume=
Left volume value, range 0.0 to 1.0android :: SoundPool :: load_name
Load a sound by itsname
in the resources, the sound must be in the res/raw
folder
android :: SoundPool :: max_streams
The maximum number of simultaneous streams for this SoundPoolandroid :: SoundPool :: max_streams=
The maximum number of simultaneous streams for this SoundPoolcore :: Object :: output_class_name
Display class name on stdout (debug only).android :: SoundPool :: right_volume=
Right volume value, range 0.0 to 1.0android :: SoundPool :: src_quality
The sample-rate converter quality, currently has no effectandroid :: SoundPool :: src_quality=
The sample-rate converter quality, currently has no effectandroid :: SoundPool :: stream_loop=
Set loop mode on a streamandroid :: SoundPool :: stream_priority=
Change stream priorityandroid :: SoundPool :: stream_rate=
Change playback rateandroid :: SoundPool :: stream_type
The audio stream type, 3 is STREAM_MUSIC, default for game applicationandroid :: SoundPool :: stream_type=
The audio stream type, 3 is STREAM_MUSIC, default for game applicationandroid :: SoundPool :: stream_volume
Set stream volume
# Used to play sound, best suited for sounds effects in apps or games
class SoundPool
# Latest error on this sound pool
var error: nullable Error = null
private var nsoundpool: NativeSoundPool is noinit
# The maximum number of simultaneous streams for this SoundPool
var max_streams = 10 is writable
# The audio stream type, 3 is STREAM_MUSIC, default for game application
var stream_type = 3 is writable
# The sample-rate converter quality, currently has no effect
var src_quality = 0 is writable
# Left volume value, range 0.0 to 1.0
var left_volume = 1.0 is writable
# Right volume value, range 0.0 to 1.0
var right_volume = 1.0 is writable
# Playback rate, 1.0 = normal playback, range 0.5 to 2.0
var rate = 1.0 is writable
# Loop mode, 0 = no loop, -1 = loop forever
var looping = 0 is writable
# Stream priority
private var priority = 1
init do self.nsoundpool = (new NativeSoundPool(max_streams, stream_type, src_quality)).new_global_ref
# Load the sound from an asset file descriptor
# this function is for advanced use
private fun load_asset_fd(afd: NativeAssetFileDescriptor): Sound do
var resval = nsoundpool.load_asset_fd(afd, self.priority)
if resval == -1 then
self.error = new Error("Unable to load sound from assets")
return new Sound.priv_init(null, -1, self, self.error)
else
return new Sound.priv_init(null, resval, self, null)
end
end
# Returns only the id corresponding to the soundpool where the sound is loaded.
# Needed by `load` of `Sound`.
private fun load_asset_fd_rid(afd: NativeAssetFileDescriptor): Int do
return nsoundpool.load_asset_fd(afd, self.priority)
end
# Load the sound from its resource id
fun load_id(context: NativeActivity, id:Int): Sound do
var resval = nsoundpool.load_id(context, id, priority)
if resval == -1 then
self.error = new Error("Unable to load sound from assets")
return new Sound.priv_init(null, -1, self, self.error)
else
return new Sound.priv_init(null, resval, self, null)
end
end
# Returns only the id corresponding to the soundpool where the sound is loaded.
private fun load_id_rid(context: NativeActivity, id: Int): Int do
return nsoundpool.load_id(context, id, priority)
end
# Load the sound from the specified path
fun load_path(path: String): Sound do
sys.jni_env.push_local_frame(1)
var resval = nsoundpool.load_path(path.to_java_string, priority)
sys.jni_env.pop_local_frame
if resval == -1 then
self.error = new Error("Unable to load sound from path: " + path)
return new Sound.priv_init(null, -1, self, self.error)
else
return new Sound.priv_init(null, resval, self, null)
end
end
# Play a sound from a sound ID
# return non-zero streamID if successful, zero if failed
fun play(id: Int): Int do
return nsoundpool.play(id, left_volume, right_volume, priority, looping, rate)
end
# Load a sound by its `name` in the resources, the sound must be in the `res/raw` folder
fun load_name(resource_manager: ResourcesManager, context: NativeActivity, name: String): Sound do
var id = resource_manager.raw_id(name)
var resval = nsoundpool.load_id(context, id, priority)
if resval == -1 then
self.error = new Error("Unable to load sound from resources: " + name)
return new Sound.priv_init(null, -1, self, self.error)
else
return new Sound.priv_init(null, resval, self, null)
end
end
# Returns only the id corresponding to the soundpool where the sound is loaded.
private fun load_name_rid(resource_manager: ResourcesManager, context: NativeActivity, sound: String): Int do
var id = resource_manager.raw_id(sound)
return nsoundpool.load_id(context, id, priority)
end
# Pause a playback stream
fun pause_stream(stream_id: Int) do nsoundpool.pause(stream_id)
# Pause all active_streams
fun auto_pause do nsoundpool.auto_pause
# Resume all previously active streams
fun auto_resume do nsoundpool.auto_resume
# Resume a playback stream
fun resume(stream_id: Int) do nsoundpool.resume(stream_id)
# Set loop mode on a stream
fun stream_loop=(stream_id, looping: Int) do nsoundpool.set_loop(stream_id, looping)
# Change stream priority
fun stream_priority=(stream_id, priority: Int) do nsoundpool.set_priority(stream_id, priority)
# Change playback rate
fun stream_rate=(stream_id: Int, rate: Float) do nsoundpool.set_rate(stream_id, rate)
# Set stream volume
fun stream_volume(stream_id: Int, left_volume, right_volume: Float) do
nsoundpool.set_volume(stream_id, left_volume, right_volume)
end
# Stop a playback stream
fun stop_stream(stream_id: Int) do nsoundpool.stop(stream_id)
# Unload a sound from a sound ID
fun unload(sound: Sound): Bool do return nsoundpool.unload(sound.soundpool_id)
# Destroys the object
fun destroy do nsoundpool.release
end
lib/android/audio.nit:223,1--362,3