X-Git-Url: http://nitlanguage.org diff --git a/lib/android/audio.nit b/lib/android/audio.nit index 6cec4e1..b361b4f 100644 --- a/lib/android/audio.nit +++ b/lib/android/audio.nit @@ -48,7 +48,7 @@ module audio import java import java::io intrude import assets_and_resources -import native_app_glue # FIXME update this module to use nit_activity +import activities import app::audio in "Java" `{ @@ -138,7 +138,6 @@ private extern class NativeMediaPlayer in "Java" `{ android.media.MediaPlayer `} self.setDataSource(fd, start_offset, length); return 1; }catch(Exception e) { - Log.e("Error loading the Media Player with a file descriptor", e.getMessage()); return 0; } `} @@ -483,7 +482,7 @@ class MediaPlayer end redef class PlayableAudio - redef init do app.add_to_sounds(self) + redef init do add_to_sounds(self) end redef class Sound @@ -537,8 +536,8 @@ redef class Sound end redef fun play do - if self.error != null then return if not is_loaded then load + if self.error != null then return soundpool.play(soundpool_id) end @@ -599,8 +598,8 @@ redef class Music end redef fun play do - if self.error != null then return if not is_loaded then load + if self.error != null then return media_player.start end @@ -617,9 +616,6 @@ end redef class App - # 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] # Returns the default MediaPlayer of the application. # When you load a music, it goes in this MediaPlayer. @@ -638,7 +634,7 @@ redef class App # Sets the stream of the app to STREAM_MUSIC. # STREAM_MUSIC is the default stream used by android apps. - private fun manage_audio_stream import native_activity, native_app_glue in "Java" `{ + private fun manage_audio_stream import native_activity in "Java" `{ App_native_activity(self).setVolumeControlStream(AudioManager.STREAM_MUSIC); `} @@ -676,27 +672,34 @@ redef class App return add_to_sounds(default_mediaplayer.load_sound(resource_manager.raw_id(music), self.native_activity)).as(Music) end - # Factorizes `sounds.add` to use it in `load_music`, `load_sound`, `load_music_from_res` and `load_sound_from_res` - private fun add_to_sounds(sound: PlayableAudio): PlayableAudio do - sounds.add(sound) - return sound - end - - redef fun pause do + redef fun on_pause do super for s in sounds do s.pause audio_manager.abandon_audio_focus end - redef fun init_window do + redef fun on_create do super audio_manager.request_audio_focus manage_audio_stream end - redef fun resume do + redef fun on_resume do super audio_manager.request_audio_focus for s in sounds do s.resume 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] + + # Factorizes `sounds.add` to use it in `load_music`, `load_sound`, `load_music_from_res` and `load_sound_from_res` + private fun add_to_sounds(sound: PlayableAudio): PlayableAudio do + sounds.add(sound) + return sound + end +end