Abstraction of a playable Audio

Introduced properties

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=

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?
fun load

app :: PlayableAudio :: load

Load this playable audio
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 resume

app :: PlayableAudio :: resume

Resume the sound

Redefined properties

redef type SELF: PlayableAudio

app $ PlayableAudio :: SELF

Type of this instance, automatically specialized in every class
redef fun error: nullable Error

ios :: audio $ PlayableAudio :: error

Last error on this sound, if any
redef fun error: nullable Error

linux :: audio $ PlayableAudio :: error

Last error on this sound, if any
redef fun error: nullable Error

android :: audio $ PlayableAudio :: error

Last error on this sound, if any
redef init init

app $ PlayableAudio :: init

redef fun load

ios :: audio $ PlayableAudio :: load

Load this playable audio
redef fun play

ios :: audio $ PlayableAudio :: play

Play 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.
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.
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 resume

app :: PlayableAudio :: resume

Resume the sound
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
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::PlayableAudio PlayableAudio core::Object Object app::PlayableAudio->core::Object app::Sound Sound app::Sound->app::PlayableAudio app::Music Music app::Music->app::PlayableAudio

Parents

interface Object

core :: Object

The root of the class hierarchy.

Children

class Music

app :: Music

Long sound that can bee looped
class Sound

app :: Sound

Short sound

Class definitions

app $ PlayableAudio
# Abstraction of a playable Audio
abstract class PlayableAudio

	init do sounds.add self

	# Path to the audio file in the assets folder
	var path: String

	# Last error on this sound, if any
	fun error: nullable Error do return null

	# Load this playable audio
	fun load do end

	# Play the sound
	fun play do end

	# Pause the sound
	fun pause do end

	# Resume the sound
	fun resume do end
end
lib/app/audio.nit:32,1--54,3

ios :: audio $ PlayableAudio
redef class PlayableAudio

	redef var error = null

	private var native: nullable AVAudioPlayer is lazy do

		# Find file
		var ns_path = ("assets"/path).to_nsstring
		var url_in_bundle = asset_url(ns_path)
		if url_in_bundle.address_is_null then
			self.error = new Error("Sound at '{path}' not found")
			return null
		end

		var player = new AVAudioPlayer.contents_of(url_in_bundle)
		# TODO set delegate to get further errors
		if player.address_is_null then
			self.error = new Error("Sound at '{path}' failed to load")
			return null
		end

		player.prepare_to_play

		return player
	end

	redef fun load do native # For lazy loading

	redef fun play
	do
		var native = native
		if native != null then native.play_and_repare_async
	end

	# Free native resources
	fun destroy
	do
		var native = native
		if native != null then native.release
	end
end
lib/ios/audio.nit:25,1--65,3

linux :: audio $ PlayableAudio
redef class PlayableAudio
	redef var error = null

	# Real file system path to this asset
	private fun fs_path: String do return app.assets_dir / path

	# Does `fs_path` exist?
	private fun fs_path_exists: Bool
	do
		if not fs_path.file_exists then
			error = new Error("Failed to load audio '{path}': file not found")
			return false
		end
		return true
	end
end
lib/linux/audio.nit:24,1--39,3

android :: audio $ PlayableAudio
redef class PlayableAudio
	# Flag to know if the user paused the sound
	# Used when the app pause all sounds or resume all sounds
	var paused: Bool = false

	# Is `self` already loaded?
	protected var is_loaded = false is writable

	redef var error = null
end
lib/android/audio.nit:510,1--519,3