app :: PlayableAudio
app :: PlayableAudio :: _error
app :: PlayableAudio :: _error
app :: PlayableAudio :: _error
app :: PlayableAudio :: _native
app :: PlayableAudio :: defaultinit
app :: PlayableAudio :: error=
app :: PlayableAudio :: error=
app :: PlayableAudio :: error=
app :: PlayableAudio :: native
app :: PlayableAudio :: native=
app :: PlayableAudio :: path=
Path to the audio file in the assets folderapp :: PlayableAudio :: paused=
Flag to know if the user paused the soundapp $ PlayableAudio :: SELF
Type of this instance, automatically specialized in every classapp $ PlayableAudio :: init
app :: PlayableAudio :: _error
app :: PlayableAudio :: _error
app :: PlayableAudio :: _error
app :: PlayableAudio :: _native
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
app :: PlayableAudio :: defaultinit
core :: Object :: defaultinit
app :: PlayableAudio :: error=
app :: PlayableAudio :: error=
app :: PlayableAudio :: error=
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.
app :: PlayableAudio :: native
app :: PlayableAudio :: native=
core :: Object :: native_class_name
The class name of the object in CString format.core :: Object :: output_class_name
Display class name on stdout (debug only).app :: PlayableAudio :: path=
Path to the audio file in the assets folderapp :: PlayableAudio :: paused=
Flag to know if the user paused the sound
# 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
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
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