Merge branch 'master' into polymorphic_extern_classes
[nit.git] / lib / android / audio.nit
index 7a19756..8d3264f 100644 (file)
@@ -22,7 +22,7 @@
 module audio
 
 import java
-import java_io
+import java::io
 import assets_and_resources
 import app
 
@@ -101,6 +101,7 @@ extern class NativeMediaPlayer in "Java" `{ android.media.MediaPlayer `}
                        e.printStackTrace();
                }
        `}
+       fun reset in "Java" `{ recv.reset(); `}
 end
 
 # Sound Pool from Java, used to play sounds simultaneously
@@ -128,32 +129,33 @@ extern class NativeSoundPool in "Java" `{ android.media.SoundPool `}
        fun set_volume(stream_id: Int, left_volume, right_volume: Float) in "Java" `{ recv.setVolume((int)stream_id, (float)left_volume, (float)right_volume); `}
        fun stop(stream_id: Int) in "Java" `{ recv.stop((int)stream_id); `}
        fun unload(sound_id: Int): Bool in "Java" `{ return recv.unload((int)sound_id); `}
+       fun release in "Java" `{ recv.release(); `}
 end
 
 
 # Used to play sound, best suited for sounds effects in apps or games
 class SoundPool
-       private var nsoundpool: NativeSoundPool
+       private var nsoundpool: NativeSoundPool is noinit
        # The maximum number of simultaneous streams for this SoundPool
-       var max_streams writable = 10
+       var max_streams = 10 is writable
 
        # The audio stream type, 3 is STREAM_MUSIC, default for game application
-       var stream_type writable = 3
+       var stream_type = 3 is writable
 
        # The sample-rate converter quality, currently has no effect
-       var src_quality writable = 0
+       var src_quality = 0 is writable
 
        # Left volume value, range 0.0 to 1.0
-       var left_volume writable = 1.0
+       var left_volume = 1.0 is writable
 
        # Right volume value, range 0.0 to 1.0
-       var right_volume writable = 1.0
+       var right_volume = 1.0 is writable
 
        # Playback rate, 1.0 = normal playback, range 0.5 to 2.0
-       var rate writable = 1.0
+       var rate = 1.0 is writable
 
        # Loop mode, 0 = no loop, -1 = loop forever
-       var looping writable = 0
+       var looping = 0 is writable
 
        # Stream priority
        private var priority = 1
@@ -222,6 +224,8 @@ class SoundPool
 
        # Unload a sound from a sound ID
        fun unload(sound: SoundSP): Bool do return nsoundpool.unload(sound.soundpool_id)
+
+       fun destroy do nsoundpool.release
 end
 
 # Used to play sounds, designed to use with medium sized sounds or streams
@@ -288,6 +292,9 @@ class MediaPlayer
                self.sound = null
        end
 
+       # Reset MediaPlayer to its initial state
+       fun reset do nmedia_player.reset
+
        # Sets the datasource (file-pathor http/rtsp URL) to use
        fun data_source(path: String): Sound do
                sys.jni_env.push_local_frame(1)
@@ -317,7 +324,6 @@ class MediaPlayer
 
        # Sets the audio stream type for this media player
        fun stream_type=(stream_type: Int) do nmedia_player.stream_type = stream_type
-
 end
 
 # Represents an android sound that can be played by a SoundPool or a MediaPlayer