1

I use MediaPlayer in service and it usually works for hours, but from time to time it give me error "-38". This is how I get it. I tried to find what that means, but I couldn´t find it. I would appreciate any advice.

Note: pathToFile is taken from MediaStore (over and over)

public void Play(String pathToFile)
   {
   mediaPlayer.reset();
   mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
   mediaPlayer.setDataSource(pathToFile);
   mediaPlayer.prepareAsync();
   }

@Override
public void onPrepared(MediaPlayer mp) 
   {
   mediaPlayer.start(); 
   }

@Override
public boolean onError(MediaPlayer mp, int what, int extra) 
    {
    switch (what) 
        {
        case MediaPlayer.MEDIA_ERROR_IO:
            ClassErrorHandler.ReportError(context, getClass().getName()+".onError","MEDIA_ERROR_IO");
            break;      
        case MediaPlayer.MEDIA_ERROR_MALFORMED:
            ClassErrorHandler.ReportError(context, getClass().getName()+".onError","MEDIA_ERROR_MALFORMED");
            break;
        case MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK:
            ClassErrorHandler.ReportError(context, getClass().getName()+".onError","MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK");
            break;
        case MediaPlayer.MEDIA_ERROR_SERVER_DIED:
            ClassErrorHandler.ReportError(context, getClass().getName()+".onError","MEDIA_ERROR_SERVER_DIED");
            break;
        case MediaPlayer.MEDIA_ERROR_TIMED_OUT:
            ClassErrorHandler.ReportError(context, getClass().getName()+".onError","MEDIA_ERROR_TIMED_OUT");
            break;
        case MediaPlayer.MEDIA_ERROR_UNKNOWN:
            ClassErrorHandler.ReportError(context, getClass().getName()+".onError","MEDIA_ERROR_UNKNOWN");
            break;
        case MediaPlayer.MEDIA_ERROR_UNSUPPORTED:
            ClassErrorHandler.ReportError(context, getClass().getName()+".onError","MEDIA_ERROR_UNSUPPORTED");
            break;              
        case MediaPlayer.MEDIA_INFO_BAD_INTERLEAVING:
            ClassErrorHandler.ReportError(context, getClass().getName()+".onError","MEDIA_INFO_BAD_INTERLEAVING");
            break;
        case MediaPlayer.MEDIA_INFO_BUFFERING_END:
            ClassErrorHandler.ReportError(context, getClass().getName()+".onError","MEDIA_INFO_BUFFERING_END");
            break;
        case MediaPlayer.MEDIA_INFO_BUFFERING_START:
            ClassErrorHandler.ReportError(context, getClass().getName()+".onError","MEDIA_INFO_BUFFERING_START");
            break;
        case MediaPlayer.MEDIA_INFO_METADATA_UPDATE:
            ClassErrorHandler.ReportError(context, getClass().getName()+".onError","MEDIA_INFO_METADATA_UPDATE");
            break;
        case MediaPlayer.MEDIA_INFO_NOT_SEEKABLE:
            ClassErrorHandler.ReportError(context, getClass().getName()+".onError","MEDIA_INFO_NOT_SEEKABLE");
            break;
        case MediaPlayer.MEDIA_INFO_SUBTITLE_TIMED_OUT:
            ClassErrorHandler.ReportError(context, getClass().getName()+".onError","MEDIA_INFO_SUBTITLE_TIMED_OUT");
            break;
        case MediaPlayer.MEDIA_INFO_UNSUPPORTED_SUBTITLE:
            ClassErrorHandler.ReportError(context, getClass().getName()+".onError","MEDIA_INFO_UNSUPPORTED_SUBTITLE");
            break;
        case MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START:
            ClassErrorHandler.ReportError(context, getClass().getName()+".onError","MEDIA_INFO_VIDEO_RENDERING_START");
            break;
        case MediaPlayer.MEDIA_INFO_VIDEO_TRACK_LAGGING:
            ClassErrorHandler.ReportError(context, getClass().getName()+".onError","MEDIA_INFO_VIDEO_TRACK_LAGGING");
            break;
        default:
            ClassErrorHandler.ReportError(context, getClass().getName()+".onError",Integer.toString(what));
            break;
        }
    return false;
    }
Michal
  • 2,071
  • 19
  • 30
  • 1
    -38 equals `-ENOSYS`, which in Android means `INVALID_OPERATION`. – Michael Nov 19 '13 at 13:36
  • possible duplicate of [Media Player called in state 0, error (-38,0)](http://stackoverflow.com/questions/9008770/media-player-called-in-state-0-error-38-0) – Mohamed_AbdAllah Nov 19 '13 at 13:38
  • -38 from the MediaPlayer is an invalid state transition. Your code here looks ok, so you'd have to provide more context to see how you get it. – Dave Nov 20 '13 at 12:12
  • 3
    It seems I sometimes called mediaPlayer.getDuration() but mediaPlayer wasn´t "ready" (for example it was in process of change to next song). – Michal Nov 21 '13 at 09:04
  • possible duplicate of [Android MediaPlayer Problems :"Error (-38 , 0) " and "stop called in state 1"](http://stackoverflow.com/questions/11913108/android-mediaplayer-problems-error-38-0-and-stop-called-in-state-1) – rds Jun 22 '15 at 08:55

0 Answers0