Android media player error (38,0)

android multimedia programs, mediaplayer (-38, 0) error occurs when mediaplayer is called when mediaplayer is not synchronized (Prepared), or getDuration method is called.

A good solution is to set up the OnPreparedLisnter listener:

MediaPlayer.OnPreparedListener preparedListener = new MediaPlayer.OnPreparedListener() {

    @Override
    public void onPrepared(MediaPlayer mp) {
        mp.start();
        total = mp.getDuration();// 总时长
    }
};
mp.setOnPreparedListener(preparedListener);
mp.prepare();

This ensures that the start and getDuration methods are called after prepare.

Read More: