audio: move some services between the abstraction and the Android layers
authorAlexis Laferrière <alexis.laf@xymus.net>
Thu, 25 May 2017 23:59:01 +0000 (19:59 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Fri, 26 May 2017 13:07:59 +0000 (09:07 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/android/audio.nit
lib/app/audio.nit

index 86e019a..a8d0afe 100644 (file)
@@ -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
index 0f1ab76..b26ae7b 100644 (file)
@@ -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