Long sound that can bee looped

Introduced properties

init defaultinit(path: String)

app :: Music :: defaultinit

fun id: nullable Int

app :: Music :: id

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

app :: Music :: id=

Resource ID of this sound
fun media_player: MediaPlayer

app :: Music :: media_player

The MediaPlayer who loaded this sound
protected fun media_player=(media_player: MediaPlayer)

app :: Music :: media_player=

The MediaPlayer who loaded this sound

Redefined properties

redef type SELF: Music

app $ Music :: SELF

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

linux :: audio $ Music :: load

Load this playable audio
redef fun load

android :: audio $ Music :: load

Load this playable audio
redef fun pause

linux :: audio $ Music :: pause

Pause the sound
redef fun pause

android :: audio $ Music :: pause

Pause the sound
redef fun play

linux :: audio $ Music :: play

Play the sound
redef fun play

android :: audio $ Music :: play

Play the sound
redef fun resume

linux :: audio $ Music :: resume

Resume the sound
redef fun resume

android :: audio $ Music :: 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 :: Music :: 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 :: Music :: id

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

app :: Music :: 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
fun media_player: MediaPlayer

app :: Music :: media_player

The MediaPlayer who loaded this sound
protected fun media_player=(media_player: MediaPlayer)

app :: Music :: media_player=

The MediaPlayer who loaded this sound
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::Music Music app::PlayableAudio PlayableAudio app::Music->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 $ Music
# Long sound that can bee looped
class Music
	super PlayableAudio
end
lib/app/audio.nit:61,1--64,3

linux :: audio $ Music
redef class Music

	private var native: nullable MixMusic = null

	redef fun load
	do
		if not fs_path_exists then return

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

		self.native = native
	end

	redef fun play
	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
		native = self.native
		assert native != null

		# Play looping
		mix.play_music(native, -1)
	end

	redef fun pause do mix.pause_music

	redef fun resume do mix.resume_music
end
lib/linux/audio.nit:88,1--131,3

android :: audio $ Music
redef class Music

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

	# The MediaPlayer who loaded this sound
	var media_player: MediaPlayer is noinit

	private init priv_init(id: nullable Int, media_player: MediaPlayer, error: nullable Error) is nosuper do
		self.id = id
		self.media_player = media_player
		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.resource_manager.raw_id(path.strip_extension)
		if rid > 0 then
			var mp_sound_resources = app.default_mediaplayer.load_sound(rid, app.native_activity)
			if mp_sound_resources.error != null then
				self.media_player = app.default_mediaplayer
				self.error = null
				self.media_player.error = null
			end
			self.error = mp_sound_resources.error
		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 mp_sound_assets = app.default_mediaplayer.data_source_fd(nam)
				nam.close
				if mp_sound_assets.error != null then
					self.error = mp_sound_assets.error
				else
					self.media_player = app.default_mediaplayer
					self.error = null
					self.media_player.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
		media_player.start
	end

	redef fun pause do
		if self.error != null or not self.is_loaded then return
		media_player.pause
		paused = true
	end

	redef fun resume do
		if self.error != null or not self.is_loaded then return
		play
		paused = false
	end
end
lib/android/audio.nit:597,1--668,3