Media player setNextPlayer

I need to loop the sound in the background without spaces. I tried many solutions like

SoundPool (-1 for loop)
AudioTrack
Mediaplayer

but did not find a better solution

now i implemented

setNextMediaPlayer()

like this

        public void createDefaultPlayer()
        {
            defaultBgSound1 = MediaPlayer.create(getApplicationContext(), getResources().getIdentifier("raw/" + file, "raw", getPackageName()));
            defaultBgSound2 = MediaPlayer.create(getApplicationContext(), getResources().getIdentifier("raw/" + file, "raw", getPackageName()));                
            defaultBgSound1.setNextMediaPlayer(defaultBgSound2);
            defaultBgSound1.start();
        }

it plays the next sound, but I want to continue this cycle forever

best way for this loop

+3
source share
1 answer

A few ideas:

1) This is how I think you suggested working:

Start exactly the same as you, preparing two copies MediaPlayerwith the same medium.

A call setNextMediaPlayereach time passing another as a parameter.

onCompletion stop() prepareAsync() . , , , setNextMediaPlayer. , , onPrepared, , .

seekTo(0) onCompletion, stop()/prepareAsync(). , , setNextMediaPlayer, MediaPlayer . ( , .)

, MediaPlayer , , setNextMediaPlayer . , onPrepared, MediaPlayer .

2) MediaPlayer seekTo(0) start() onCompletion. , , , , . , .

3) OpenSL . , :)

+2

All Articles