Android Mediaplayer/Videoview Error (1, -2147483648)

Android MediaPlayer Error (1,-22)

It seems to issue appears because I didn't call MediaPlayer.release() when onCompletion callback. As a result resources of MP did not released and finally MP crashed with the error.

Android VideoView Error 1,0

UThis is connected to your SurfaceView.
Make sure you don't touch the SurfaceView after you have called prepare on you MediaPlayer and that it is visible. In your case where you try to wake up the screen make sure that everything happens in the correct order. So preparing the MediaPlayer for playback is the very last thing which your app should do. It could be that the prepare/playback is initiated prior to the app being fully awake, causing the app to attempt to manipulate the SurfaceView.

The follow code example illustrates how to trigger that kind of exception:

   private void setupVideo(String file){
...
mSurfaceView = (SurfaceView) findViewById(R.id.surface);
mHolder = mSurfaceView.getHolder(); // DON'T TOUCH BEHIND THIS POINT
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mMediaPlayer.setDisplay(mHolder);
mMediaPlayer.setOnPreparedListener(this);
mMediaPlayer.prepare();
}
@Override
public void onPrepared(final MediaPlayer mp) {
mSurfaceView.setVisibility(View.VISIBLE); // THIS WILL CAUSE THE ERROR
mp.start();
}

MediaPlayer Error (1, -1004)

the audio starts but after 2-3 seconds it stops with an Error that is
MediaPlayer error (1, -1004).

First, Lets understand what error (1, -1004) means. -1004 is the error code for IO error. Below reference from MediaPlayer.java source code.

/** File or network related operation errors. */
public static final int MEDIA_ERROR_IO = -1004;

This type of error comes if for some reason, the media player is not able to connect to the server due to network issues. It could be bad internet connectivity at that instance or some network related reason due which the media player was unable to connect to the server. There are some other similar error codes that the media player can throw like time-outs or server died:

/** Some operation takes too long to complete, usually more than 3-5 seconds. */
public static final int MEDIA_ERROR_TIMED_OUT = -110;
/** Media server died.*/
public static final int MEDIA_ERROR_SERVER_DIED = 100;

Now What should I do?

To handle errors generated by media player at run time, you should implement Error Listener. You can handle the error in which ever way as you like for example restart the player.

mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
switch(extra){
case MediaPlayer.MEDIA_ERROR_SERVER_DIED:
// Do Something
// eg. reset the media player and restart
break;
case MediaPlayer.MEDIA_ERROR_IO:
// Do Something
// eg. Show dialog to user indicating bad connectivity
// or attempt to restart the player
break;
case MediaPlayer.MEDIA_ERROR_TIMED_OUT:
//Do Something
//eg. Show dialog that there was error in connecting to the server
// or attempt some retries
break;
}
//You must always return true if you want the error listener to work
return true;
}
});

Mediaplayer error (-38,0) and error (1,-1010)

I fixed it by changing a part in the onResumse(),

As expected it was indeed the permission causing havoc,
i had:

if (ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED) {
if (!mPlayer.isPlaying() && !mpCreated) {
initTunnelPlayerWorkaround();
init();
} else {
mPlayer.start();
mVisualizerView.link(mPlayer);
}
} else {
cleanUp();
mPlayer.start();
Log.i("boop","biep");
}

And finally discovered by that log it was going into the else, meaning it was calling the cleanUp(); method

And in the cleanUp() method i had:

private void cleanUp() {
if (mPlayer != null) {
mVisualizerView.release();
if(!mPlayer.isPlaying()) {
mPlayer.pause();
}
}
}

The 2nd if was causing havoc (duh) and i fixed it by changing it to:

private void cleanUp() {
if (mPlayer != null) {
mVisualizerView.release();
if(mPlayer.isPlaying()) {
mPlayer.pause();
}
}

I know this is a weird and specific answer, but maybe someone else who had the same struggle can find out why he or she was having problems.

Have a great day all and thanks for trying to help

~Waro (dh19, couldnt use waro sadly)



Related Topics



Leave a reply



Submit