title: VideoView / MediaPlayer Error (1, -18)
body: <p>I have an application that is built to API level 2.2. This application contains a video that starts playing as soon as it is launched. The video is played inside a VideoView and the actually video file is stored in my internal storage (files directory for my apps package). </p>
  
  <p>Most of the time it starts up just fine. But occasionally I get an error pop - up that says "Sorry, this video cannot be played." and has an Ok button. As soon as I press the ok button the video starts playing correctly. I need to figure out what is causing this error, or at the very least how I can catch whatever error it is and have it try again since it always works perfect after I hit ok. Inside the logs when this error box is shown I see these messages:</p>
  
  <pre><code> ERROR/PVOMXAudDecNode(21215): Ln 2232 OMX_EventError nData1 -2147479547 nData2 0
   ERROR/PlayerDriver(21215): Command PLAYER_PREPARE completed with an error or info -18
   ERROR/MediaPlayer(9282): message received msg=100, ext1=1, ext2=-18
   ERROR/MediaPlayer(9282): error (1, -18)
   ERROR/MediaPlayer(9282): callback application
   ERROR/MediaPlayer(9282): back from callback
   ERROR/MediaPlayer(9282): Error (1,-18)
   DEBUG/VideoView(9282): Error: 1,-18
  </code></pre>
  
  <p>Where can I find a reference as to what exactly error code -18 indicates? And does anyone have any suggestions I could try to prevent it from happening in the first place. I have only observed This error on the Sprint Epic 4g.</p>
  
  <p>Edit: well as far as I can tell no exceptions are getting thrown to me. I assume what is happening is that the video view knows to catch whatever exception is causing and it throws up the pop-up. Inside my log there is no exception stack trace just this reference to error -18.</p>
  
  <p>As for how I am calling prepare. I use this:</p>
  
  <pre><code>    mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
          @Override
          public void onPrepared(MediaPlayer arg0) {
               mVideoView.start();
          }
      });
  </code></pre>
  
  <p>and this:</p>
  
  <pre><code>mVideoView.setVideoPath(file.getAbsolutePath());
  </code></pre>
  
  <p>it calls prepare as part of setVideoPath (I assume it does anyway, but this method is undocumented). which causes onPrepared to get called in my listener.</p>
  
  <p>Edit 2: for now i've just added an onErrorListener like so:</p>
  
  <p><strong>EDIT IMORTANT! this code will infinte error loop on ICS. For ICS devices I took out the setPath call, and returned false instead. It tries again by itself once and it succeeds.</strong>    </p>
  
  <pre><code>    mVideoView.setOnErrorListener(new OnErrorListener(){
  
          @Override
          public boolean onError(MediaPlayer arg0, int arg1, int arg2) {
              Log.i(myTag, "MP ERROR: "+ arg1 + " - " + arg2);
              mVideoView.setVideoPath(file.getAbsolutePath());
              return true;
          }
  
      });
  </code></pre>
  
  <p>this catches the error and I can see in my logs that arg2 = -18 when this error happens. I just have it retry and return true so it doesn't throw up the dialog. So far i've never seen it fail twice in a row so this always starts the video correctly and doesn't make infinite loop.</p>
  
  <p>I am still very interested if anyone can tell me exactly what error code -18 indicates though.</p>