Any one Help for MediaPlayer Error. when aim is to Change DataSource and Play second Audio when First Audio is Compliting its Playing.
My Code is below :- mMediaPlayer.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer arg0)
{
String fileName = Environment.getExternalStorageDirectory().getAbsolutePath() + FILENAME+arrListSize+".wav";
mMediaPlayer.release();
mMediaPlayer = null;
mMediaPlayer = new MediaPlayer();
Uri uri = Uri.parse("file://"+fileName); mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try
{
mMediaPlayer.setDataSource(getApplicationContext(), uri);
mMediaPlayer.prepare();
}
catch (Exception e)
{
e.printStackTrace();
}
Error :- setDataSource called in state 32
Thanks.
From the error, it looks like the previous instance of the
MediaPlayer
is not released completely. When the playback has completed, the player is in Paused state when theonCompletionListener
is invoked. Can you pleasestop
theMediaPlayer
before releasing the same?