Error (-38.0) on Media Player Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Error (-38.0) on Media Player without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I am making a simple media player application. It involes a textfield (et) where user just enters the exact name of the song to be played and presses the play button (ib1) to be played. Songs are saved inside sdcard. My code is:

ib1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final String value = et.getText().toString();
            String full_path = "/mnt/media_rw/sdcard/mymusic/" + value + ".mp3";
            et.setText("");

            mp = new MediaPlayer();                     
            mp.setDataSource(full_path);
            mp.prepare();
            mp.start();                             


} });

But this produces Media Player error (-38.0). So, following Media Player called in state 0, error (-38,0) I tried to replace the mp lines with:

mp.setDataSource(full_path); 
mp.setOnPreparedListener(null);
mp.prepareAsync();
mp.start();

But it won’t work either, producing error (1, -2147483648). Can someone help me or make some suggestions for the code? Thanks a lot

Answer

You need to call mediaPlayer.start() in the onPrepared method by using a listener. You are getting this error because you are calling mp.start() before it has reached the prepared state.

Here is how you can do it :

mp.setDataSource(full_path); 
mp.setOnPreparedListener(this);
mp.prepareAsync();

public void onPrepared(MediaPlayer player) {
player.start();
}
We are here to answer your question about Error (-38.0) on Media Player - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji