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;
}
`}
end
redef class PlayableAudio
- redef init do app.add_to_sounds(self)
+ redef init do add_to_sounds(self)
end
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
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
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.
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 on_pause do
super
for s in sounds do s.pause
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