2

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!

  • i mean more like resource efficient. Something that would not cause any memory issues and is standard for playing 1 audio file in a loop in android? –  Feb 13 '18 at 01:30
  • Using an .mp3 file format probably could make you gain some kbytes on final project. – statosdotcom Feb 13 '18 at 01:33
  • @statosdotcom but even with or without it, is mediaplayer the best alternative to use ? or is there some sort of audioplayer that is better and resource efficient –  Feb 13 '18 at 02:05
  • Can you explain why you think `MediaPlayer` is not that efficient? – GGWP Feb 13 '18 at 02:18
  • @MarissaNicholas I don't think even if there is an alternative to mediaplayer at the original Android API. What you could do is try to investigate ways for building your own super power optimized and resource saver native mediaplayer (i.e.: using C++ on your Android Studio's NDK). In case of success, please, return here to show us your goals. Best luck. – statosdotcom Feb 13 '18 at 02:31
  • @GGWP I was reading about audioplayers, like exoplayers and AudioPlayer and was wondering they are more efficient than mediaplayer for this particular instance/scenario I am facing. –  Feb 13 '18 at 02:42
  • any of you guys have any idea about this one : https://stackoverflow.com/questions/49302694/how-do-i-detect-skype-telegram-whatsapp-calls-when-my-messenger-app-is-in-a-call –  Mar 19 '18 at 18:08

0 Answers0