Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I detect that MediaPlayer object starts playing?

I'm working with setNextMediaPlayer() method to make a gapless playback music player.

setNextMediaPlayer() is a great method to enable gapless playback but there was a problem for me to refresh the information of the next coming song to layouts. When I use setNextMediaPlayer() method, I don't need to use start() method to start playback so there's no way to catch when the playback starts exactly. Alternatively, I put my information refreshing method in onCompletion but it has a limit.

public void onCompletion(MediaPlayer mp) {
    Log.d(TAG, "onCompletion():");
    displayInfoSingle(nextItem);//refresh albumart and song info.
}

Is there any listener to detect when MediaPlayer object starts playback?

Added after Tarun Varshney's answer>>>

I'm using setNextMediaPlayer() as below to play mp2 next to mp1 seamlessly.

mp2 = new MediaPlayer();
mp2.setDataSource(nextItem.getUri());
mp2.setOnCompletionListener(this);
mp2.prepare();
mp1.setNextMediaPlayer(mp2);

mp2 already might be prepared before its playback because of **mp2.prepare();** so onPreparedListener will not be called at the right time I want. Is there any other way to set mp2 as a parameter of setNextMediaPlayer of mp1?

like image 247
Aerok Avatar asked Jul 23 '13 05:07

Aerok


1 Answers

public void setOnPreparedListener (MediaPlayer.OnPreparedListener listener)

This might work for you.

like image 94
T_V Avatar answered Sep 30 '22 06:09

T_V