Shruthi Rajan
Shruthi Rajan

Reputation: 21

OnCompletionListener not working once mediaplayer is reinitialized

mySound.setOnCompletionListener(new OnCompletionListener() {
 @Override
 public void onCompletion(MediaPlayer mp) {
          mp.release();...
 }

The code works fine if mySound is not changed. But when mySound is released and reinitialized, the code no longer works.

Upvotes: 0

Views: 1074

Answers (1)

Ali Gorji
Ali Gorji

Reputation: 327

Quoted by Google:

When done with the MediaPlayer, you should call release(), to free the resources. If not released, too many MediaPlayer instances will result in an exception.

after call release(), and if you need use this again, you must create new instance of MediaPlayer and re-initialization, also including setOnCompletionListener.

mPlayer.release();
mPlayer = null;  

mPlayer = new MediaPlayer();
...
mPlayer.setOnCompletionListener(new OnCompletionListener()
{
    @Override
    public void onCompletion(MediaPlayer mp)
    {

    }
});

Upvotes: 2

Related Questions