Currently I am using a mediaplayer to play one single audio file in a loop when a button is clicked( stops playing when a certain event is triggered or onstop). However, I am not sure if mediaplayer is ideal for playing 1 audio sound worth 8-10 seconds set to loop to a max of 30seconds. Is there a better and resource efficient alternative I can use? Any examples would help.
Here's my code so far:
MediaPlayer mp;
onCreate(savedinstance){
....
mp = MediaPlayer.create(getBaseContext(), R.raw.ringbacktone);
mp.setLooping(true);
mp.setVolume(100, 100);
...
}
public void somefunction {
...
case someeventhappens:
mp.start();
break;
...}
@Override
public void onStop() {
super.onStop();
mp.stop();
}
@Override
protected void onDestroy() {
super.onDestroy();
if(mp != null) {
mp.stop();
}
Any idea how I can improve this or use a better resource efficient alternative to best suit my needs of just playing a .wav file ?
Thanks in advance!