Short sound

Introduced properties

init defaultinit(path: String)

app :: Sound :: defaultinit

fun id: nullable Int

app :: Sound :: id

Resource ID of this sound
protected fun id=(id: nullable Int)

app :: Sound :: id=

Resource ID of this sound
fun play_channel(channel: Int, loops: Int): Int

app :: Sound :: play_channel

Play this sound on channel (or any channel if -1) and return the channel
fun soundpool: SoundPool

app :: Sound :: soundpool

The SoundPool who loaded this sound
protected fun soundpool=(soundpool: SoundPool)

app :: Sound :: soundpool=

The SoundPool who loaded this sound
fun soundpool_id: Int

app :: Sound :: soundpool_id

The SoundID of this sound in his SoundPool
protected fun soundpool_id=(soundpool_id: Int)

app :: Sound :: soundpool_id=

The SoundID of this sound in his SoundPool

Redefined properties

redef type SELF: Sound

app $ Sound :: SELF

Type of this instance, automatically specialized in every class
redef fun load

linux :: audio $ Sound :: load

Load this playable audio
redef fun load

android :: audio $ Sound :: load

Load this playable audio
redef fun pause

android :: audio $ Sound :: pause

Pause the sound
redef fun play

android :: audio $ Sound :: play

Play the sound
redef fun play

linux :: audio $ Sound :: play

Play the sound
redef fun resume

android :: audio $ Sound :: resume

Resume the sound

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
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.
init defaultinit(path: String)

app :: Sound :: defaultinit

fun destroy

app :: PlayableAudio :: destroy

Free native resources
fun error: nullable Error

app :: PlayableAudio :: error

Last error on this sound, if any
protected fun error=(error: nullable Error)

app :: PlayableAudio :: error=

protected fun error=(error: nullable Error)

app :: PlayableAudio :: error=

protected fun error=(error: nullable Error)

app :: PlayableAudio :: error=

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.
fun id: nullable Int

app :: Sound :: id

Resource ID of this sound
protected fun id=(id: nullable Int)

app :: Sound :: id=

Resource ID of this sound
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".
protected fun is_loaded: Bool

app :: PlayableAudio :: is_loaded

Is self already loaded?
fun is_loaded=(is_loaded: Bool)

app :: PlayableAudio :: is_loaded=

Is self already loaded?
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 load

app :: PlayableAudio :: load

Load this playable audio
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 path: String

app :: PlayableAudio :: path

Path to the audio file in the assets folder
protected fun path=(path: String)

app :: PlayableAudio :: path=

Path to the audio file in the assets folder
fun pause

app :: PlayableAudio :: pause

Pause the sound
fun paused: Bool

app :: PlayableAudio :: paused

Flag to know if the user paused the sound
protected fun paused=(paused: Bool)

app :: PlayableAudio :: paused=

Flag to know if the user paused the sound
fun play

app :: PlayableAudio :: play

Play the sound
fun play_channel(channel: Int, loops: Int): Int

app :: Sound :: play_channel

Play this sound on channel (or any channel if -1) and return the channel
fun resume

app :: PlayableAudio :: resume

Resume the sound
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
fun soundpool: SoundPool

app :: Sound :: soundpool

The SoundPool who loaded this sound
protected fun soundpool=(soundpool: SoundPool)

app :: Sound :: soundpool=

The SoundPool who loaded this sound
fun soundpool_id: Int

app :: Sound :: soundpool_id

The SoundID of this sound in his SoundPool
protected fun soundpool_id=(soundpool_id: Int)

app :: Sound :: soundpool_id=

The SoundID of this sound in his SoundPool
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.
package_diagram app::Sound Sound app::PlayableAudio PlayableAudio app::Sound->app::PlayableAudio core::Object Object app::PlayableAudio->core::Object ...core::Object ... ...core::Object->core::Object

Ancestors

interface Object

core :: Object

The root of the class hierarchy.

Parents

abstract class PlayableAudio

app :: PlayableAudio

Abstraction of a playable Audio

Class definitions

app $ Sound
# Short sound
class Sound
	super PlayableAudio
end
lib/app/audio.nit:56,1--59,3

linux :: audio $ Sound
redef class Sound

	private var native: nullable MixChunk = null

	redef fun load
	do
		if not fs_path_exists then return

		# SDL2 mixer load
		var native = mix.load_wav(fs_path.to_cstring)
		if native.address_is_null then
			error = new Error("Failed to load sound '{path}': {mix.error}")
			return
		end

		self.native = native
	end

	redef fun play do play_channel(-1, 0)

	# Play this sound on `channel` (or any channel if -1) and return the channel
	#
	# Repeat the sound `loops` times, `loops == 0` plays it once,
	# `loops == 1` plays it twice and `loops == -1` loops infinitely.
	fun play_channel(channel, loops: Int): Int
	do
		var native = native

		if native == null and error == null then
			# Lazy load
			load

			# Auto print errors on lazy loading only
			var error = error
			if error != null then print_error error
		end

		# If there's an error, silently skip
		if error != null then return -1
		native = self.native
		assert native != null

		# Play on any available channel
		return mix.play_channel(channel, native, loops)
	end
end
lib/linux/audio.nit:41,1--86,3

android :: audio $ Sound
redef class Sound

	# Resource ID of this sound
	var id: nullable Int is noinit

	# The SoundPool who loaded this sound
	var soundpool: SoundPool is noinit

	# The SoundID of this sound in his SoundPool
	var soundpool_id: Int is noinit

	private	init priv_init(id: nullable Int, soundpool_id: Int, soundpool: SoundPool, error: nullable Error) is nosuper do
		self.id = id
		self.soundpool_id = soundpool_id
		self.soundpool = soundpool
		if error != null then
			self.error = error
		else
			self.is_loaded = true
		end
	end

	redef fun load do
		if is_loaded then return

		# Try resources (res)
		var rid = app.default_soundpool.load_name_rid(app.resource_manager, app.native_activity, path.strip_extension)
		if rid > 0 then
			self.soundpool_id = rid
			self.soundpool = app.default_soundpool
			self.error = null
			self.soundpool.error = null
		else
			# Try assets
			var nam = app.asset_manager.open_fd(path)
			if nam.is_java_null then
				self.error = new Error("Failed to get file descriptor for " + path)
			else
				var retval_assets = app.default_soundpool.load_asset_fd_rid(nam)
				nam.close
				if retval_assets == -1 then
					self.error = new Error("Failed to load " + path)
				else
					self.soundpool_id = retval_assets
					self.soundpool = app.default_soundpool
					self.error = null
					self.soundpool.error = null
				end
			end
		end
		is_loaded = true

		var error = error
		if error != null then print_error error
	end

	redef fun play do
		if not is_loaded then load
		if self.error != null then return
		soundpool.play(soundpool_id)
	end

	redef fun pause do
		if self.error != null or not self.is_loaded then return
		soundpool.pause_stream(soundpool_id)
		paused = true
	end

	redef fun resume do
		if self.error != null or not self.is_loaded then return
		soundpool.resume(soundpool_id)
		paused = false
	end

end
lib/android/audio.nit:521,1--595,3