From 7e04c4b45f9753f82a1e4045d9a8593662514424 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Thu, 25 May 2017 19:59:01 -0400 Subject: [PATCH] audio: move some services between the abstraction and the Android layers MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- lib/android/audio.nit | 21 ++++++--------------- lib/app/audio.nit | 13 +++++++++---- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/lib/android/audio.nit b/lib/android/audio.nit index 86e019a..a8d0afe 100644 --- a/lib/android/audio.nit +++ b/lib/android/audio.nit @@ -498,7 +498,10 @@ redef class PlayableAudio # Used when the app pause all sounds or resume all sounds var paused: Bool = false - redef init do sounds.add self + # Is `self` already loaded? + protected var is_loaded = false is writable + + redef var error = null end redef class Sound @@ -642,7 +645,6 @@ end redef class App - # Returns the default MediaPlayer of the application. # When you load a music, it goes in this MediaPlayer. # Use it for advanced sound management @@ -666,16 +668,12 @@ redef class App # Same as `load_sound` but load the sound from the `res/raw` folder fun load_sound_from_res(sound_name: String): Sound do - var sound = default_soundpool.load_name(resource_manager,self.native_activity, sound_name) - sys.sounds.add sound - return sound + return default_soundpool.load_name(resource_manager, native_activity, sound_name) end # Same as `load_music` but load the sound from the `res/raw` folder fun load_music_from_res(music: String): Music do - var sound = default_mediaplayer.load_sound(resource_manager.raw_id(music), self.native_activity) - sys.sounds.add sound - return sound + return default_mediaplayer.load_sound(resource_manager.raw_id(music), native_activity) end redef fun on_pause do @@ -708,10 +706,3 @@ redef class App end end end - -redef class Sys - - # Sounds handled by the application, when you load a sound, it's added to this list. - # This array is used in `pause` and `resume` - private var sounds = new Array[PlayableAudio] -end diff --git a/lib/app/audio.nit b/lib/app/audio.nit index 0f1ab76..b26ae7b 100644 --- a/lib/app/audio.nit +++ b/lib/app/audio.nit @@ -31,14 +31,13 @@ import android::audio is conditional(android) # 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 - var error: nullable Error = null is writable - - # Is `self` already loaded? - protected var is_loaded = false is writable + fun error: nullable Error do return null # Load this playable audio fun load do end @@ -62,3 +61,9 @@ end class Music super PlayableAudio end + +redef class Sys + + # All instantiated sounds + var sounds = new Array[PlayableAudio] +end -- 1.7.9.5