Used to play sound, best suited for sounds effects in apps or games

Introduced properties

fun auto_pause

android :: SoundPool :: auto_pause

Pause all active_streams
fun auto_resume

android :: SoundPool :: auto_resume

Resume all previously active streams
fun destroy

android :: SoundPool :: destroy

Destroys the object
fun error: nullable Error

android :: SoundPool :: error

Latest error on this sound pool
protected fun error=(error: nullable Error)

android :: SoundPool :: error=

Latest error on this sound pool
fun left_volume: Float

android :: SoundPool :: left_volume

Left volume value, range 0.0 to 1.0
fun left_volume=(left_volume: Float)

android :: SoundPool :: left_volume=

Left volume value, range 0.0 to 1.0
fun load_id(context: NativeActivity, id: Int): Sound

android :: SoundPool :: load_id

Load the sound from its resource id
fun load_name(resource_manager: ResourcesManager, context: NativeActivity, name: String): Sound

android :: SoundPool :: load_name

Load a sound by its name in the resources, the sound must be in the res/raw folder
fun load_path(path: String): Sound

android :: SoundPool :: load_path

Load the sound from the specified path
fun looping: Int

android :: SoundPool :: looping

Loop mode, 0 = no loop, -1 = loop forever
fun looping=(looping: Int)

android :: SoundPool :: looping=

Loop mode, 0 = no loop, -1 = loop forever
fun max_streams: Int

android :: SoundPool :: max_streams

The maximum number of simultaneous streams for this SoundPool
fun max_streams=(max_streams: Int)

android :: SoundPool :: max_streams=

The maximum number of simultaneous streams for this SoundPool
fun pause_stream(stream_id: Int)

android :: SoundPool :: pause_stream

Pause a playback stream
fun play(id: Int): Int

android :: SoundPool :: play

Play a sound from a sound ID
fun rate: Float

android :: SoundPool :: rate

Playback rate, 1.0 = normal playback, range 0.5 to 2.0
fun rate=(rate: Float)

android :: SoundPool :: rate=

Playback rate, 1.0 = normal playback, range 0.5 to 2.0
fun resume(stream_id: Int)

android :: SoundPool :: resume

Resume a playback stream
fun right_volume: Float

android :: SoundPool :: right_volume

Right volume value, range 0.0 to 1.0
fun right_volume=(right_volume: Float)

android :: SoundPool :: right_volume=

Right volume value, range 0.0 to 1.0
fun src_quality: Int

android :: SoundPool :: src_quality

The sample-rate converter quality, currently has no effect
fun src_quality=(src_quality: Int)

android :: SoundPool :: src_quality=

The sample-rate converter quality, currently has no effect
fun stop_stream(stream_id: Int)

android :: SoundPool :: stop_stream

Stop a playback stream
fun stream_loop=(stream_id: Int, looping: Int)

android :: SoundPool :: stream_loop=

Set loop mode on a stream
fun stream_priority=(stream_id: Int, priority: Int)

android :: SoundPool :: stream_priority=

Change stream priority
fun stream_rate=(stream_id: Int, rate: Float)

android :: SoundPool :: stream_rate=

Change playback rate
fun stream_type: Int

android :: SoundPool :: stream_type

The audio stream type, 3 is STREAM_MUSIC, default for game application
fun stream_type=(stream_type: Int)

android :: SoundPool :: stream_type=

The audio stream type, 3 is STREAM_MUSIC, default for game application
fun stream_volume(stream_id: Int, left_volume: Float, right_volume: Float)

android :: SoundPool :: stream_volume

Set stream volume
fun unload(sound: Sound): Bool

android :: SoundPool :: unload

Unload a sound from a sound ID

Redefined properties

redef type SELF: SoundPool

android $ SoundPool :: SELF

Type of this instance, automatically specialized in every class
redef init init

android $ SoundPool :: init

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
fun auto_pause

android :: SoundPool :: auto_pause

Pause all active_streams
fun auto_resume

android :: SoundPool :: auto_resume

Resume all previously active streams
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
fun destroy

android :: SoundPool :: destroy

Destroys the object
fun error: nullable Error

android :: SoundPool :: error

Latest error on this sound pool
protected fun error=(error: nullable Error)

android :: SoundPool :: error=

Latest error on this sound pool
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
fun left_volume: Float

android :: SoundPool :: left_volume

Left volume value, range 0.0 to 1.0
fun left_volume=(left_volume: Float)

android :: SoundPool :: left_volume=

Left volume value, range 0.0 to 1.0
fun load_id(context: NativeActivity, id: Int): Sound

android :: SoundPool :: load_id

Load the sound from its resource id
fun load_name(resource_manager: ResourcesManager, context: NativeActivity, name: String): Sound

android :: SoundPool :: load_name

Load a sound by its name in the resources, the sound must be in the res/raw folder
fun load_path(path: String): Sound

android :: SoundPool :: load_path

Load the sound from the specified path
fun looping: Int

android :: SoundPool :: looping

Loop mode, 0 = no loop, -1 = loop forever
fun looping=(looping: Int)

android :: SoundPool :: looping=

Loop mode, 0 = no loop, -1 = loop forever
fun max_streams: Int

android :: SoundPool :: max_streams

The maximum number of simultaneous streams for this SoundPool
fun max_streams=(max_streams: Int)

android :: SoundPool :: max_streams=

The maximum number of simultaneous streams for this SoundPool
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun pause_stream(stream_id: Int)

android :: SoundPool :: pause_stream

Pause a playback stream
fun play(id: Int): Int

android :: SoundPool :: play

Play a sound from a sound ID
fun rate: Float

android :: SoundPool :: rate

Playback rate, 1.0 = normal playback, range 0.5 to 2.0
fun rate=(rate: Float)

android :: SoundPool :: rate=

Playback rate, 1.0 = normal playback, range 0.5 to 2.0
fun resume(stream_id: Int)

android :: SoundPool :: resume

Resume a playback stream
fun right_volume: Float

android :: SoundPool :: right_volume

Right volume value, range 0.0 to 1.0
fun right_volume=(right_volume: Float)

android :: SoundPool :: right_volume=

Right volume value, range 0.0 to 1.0
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
fun src_quality: Int

android :: SoundPool :: src_quality

The sample-rate converter quality, currently has no effect
fun src_quality=(src_quality: Int)

android :: SoundPool :: src_quality=

The sample-rate converter quality, currently has no effect
fun stop_stream(stream_id: Int)

android :: SoundPool :: stop_stream

Stop a playback stream
fun stream_loop=(stream_id: Int, looping: Int)

android :: SoundPool :: stream_loop=

Set loop mode on a stream
fun stream_priority=(stream_id: Int, priority: Int)

android :: SoundPool :: stream_priority=

Change stream priority
fun stream_rate=(stream_id: Int, rate: Float)

android :: SoundPool :: stream_rate=

Change playback rate
fun stream_type: Int

android :: SoundPool :: stream_type

The audio stream type, 3 is STREAM_MUSIC, default for game application
fun stream_type=(stream_type: Int)

android :: SoundPool :: stream_type=

The audio stream type, 3 is STREAM_MUSIC, default for game application
fun stream_volume(stream_id: Int, left_volume: Float, right_volume: Float)

android :: SoundPool :: stream_volume

Set stream volume
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
fun unload(sound: Sound): Bool

android :: SoundPool :: unload

Unload a sound from a sound ID
package_diagram android::SoundPool SoundPool core::Object Object android::SoundPool->core::Object

Parents

interface Object

core :: Object

The root of the class hierarchy.

Class definitions

android $ SoundPool
# 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