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?
public void setOnPreparedListener (MediaPlayer.OnPreparedListener listener)
This might work for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With