title: MediaPlayer error (1, -1004) aka MEDIA_ERROR_IO trying to stream music on Samsung S3
body: <blockquote>
  <p><em>NOTE:</em> I'm not working at the company where I worked when I posted this question, therefore, even though some great answers might come
  in, I won't actually be testing them since I don't have a reason to
  <em>(other than promoting the community; which might cause me to do it one
  day)</em>.</p>
  <p>If however, some answer to the problem is promoted by many other
  comunity members, I might opt to select it as the correct answer for
  the problem experienced so many years after I originally posted the
  question.</p>
  <p>In the meantime, I hope some of the answers may help some of you also
  experiencing this problem. Yay for Stack Overflow!</p>
  </blockquote>
  <hr />
  <p>Our application has to stream music from an online source (I'm not at liberty to disclose that source).</p>
  <p><strong>Why does it take over 2 minutes to start streaming on the S3?</strong></p>
  <p>I've been able to figure out that the Media Player object goes into the <strong>Error state</strong> due to <strong>MEDIA_ERROR_UNKOWN</strong> - great. Doesn't help me much. So upon handling this in onError with an OnErrorListener, I reset the Media Player object and then call startPlaying which does the rest - setting the data source, etc.</p>
  <p>Members:</p>
  <pre><code>private ProgressBar playSeekBar;
  private ImageView ivPlay;
  private ImageView ivPause;
  private ImageView ivBuffer;
  private MediaPlayer mPlayer;
  private ImageView ivInfo;
  private AudioManager audio;
  </code></pre>
  <p>Initializing the Media Player (and Visualizer - which is not the issue for the purpose of this question)</p>
  <pre><code>private void initialMediaPlayerAndVisualizer() {
        Log.d(TAG, &quot;Initial Media Player and Visualizer&quot;);
      
        playSeekBar = (ProgressBar) findViewById(R.id.progressBar1);
        playSeekBar.setMax(100);
        playSeekBar.setVisibility(View.GONE);
                            
        mPlayer = new MediaPlayer();   
        
        Log.d(TAG, &quot;Create onErrorListener&quot;);
        MediaPlayer.OnErrorListener errorListener = new MediaPlayer.OnErrorListener() {
          
          @Override
          public boolean onError(MediaPlayer mp, int what, int extra) {
              Log.d(TAG, &quot;OnError - Error code: &quot;+what+&quot; Extra code: &quot;+extra);
              
              switch(what){
              case -1004:
                  Log.d(&quot;Streaming Media&quot;, &quot;MEDIA_ERROR_IO&quot;);
                  break;
              case -1007:
                  Log.d(&quot;Streaming Media&quot;, &quot;MEDIA_ERROR_MALFORMED&quot;);
                  break;
              case 200:
                  Log.d(&quot;Streaming Media&quot;, &quot;MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK&quot;);
                  break;
              case 100:
                  Log.d(&quot;Streaming Media&quot;, &quot;MEDIA_ERROR_SERVER_DIED&quot;);
                  break;
              case -110:
                  Log.d(&quot;Streaming Media&quot;, &quot;MEDIA_ERROR_TIMED_OUT&quot;);
                  break;
              case 1:
                  Log.d(&quot;Streaming Media&quot;, &quot;MEDIA_ERROR_UNKNOWN&quot;);
                  break;
              case -1010:
                  Log.d(&quot;Streaming Media&quot;, &quot;MEDIA_ERROR_UNSUPPORTED&quot;);
                  break;
              
              }
  
              switch(extra){
              case 800:
                  Log.d(&quot;Streaming Media&quot;, &quot;MEDIA_INFO_BAD_INTERLEAVING&quot;);
                  break;
              case 702:
                  Log.d(&quot;Streaming Media&quot;, &quot;MEDIA_INFO_BUFFERING_END&quot;);
                  break;
              case 701:
                  Log.d(&quot;Streaming Media&quot;, &quot;MEDIA_INFO_METADATA_UPDATE&quot;);
                  break;
              case 802:
                  Log.d(&quot;Streaming Media&quot;, &quot;MEDIA_INFO_METADATA_UPDATE&quot;);
                  break;
              case 801:
                  Log.d(&quot;Streaming Media&quot;, &quot;MEDIA_INFO_NOT_SEEKABLE&quot;);
                  break;
              case 1:
                  Log.d(&quot;Streaming Media&quot;, &quot;MEDIA_INFO_UNKNOWN&quot;);
                  break;
              case 3:
                  Log.d(&quot;Streaming Media&quot;, &quot;MEDIA_INFO_VIDEO_RENDERING_START&quot;);
                  break;
              case 700 :
                  Log.d(&quot;Streaming Media&quot;, &quot;MEDIA_INFO_VIDEO_TRACK_LAGGING&quot;);
                  break;
              
              }
              
              Log.d(&quot;Streaming Media&quot;, &quot;Reset media player&quot;);
              mPlayer.reset();
              // We need to link the visualizer view to the media player so that it displays something
                mVisualizerManager = new VisualizerManager(context); //(VisualizerView) findViewById(R.id.visualizerView);
                
                //Send the visualizerContainer to the Renderer
                visualizerRenderer = new VisualizerRenderer(arrayVisualizer);
                mVisualizerManager.addRenderer(visualizerRenderer);
                
                try {
                  startPlaying();
              } catch (IllegalStateException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
              
              return true;
          }
      };
      
      Log.d(TAG, &quot;Set error listener on Media Player object&quot;);          
       mPlayer.setOnErrorListener(errorListener);
       
        // We need to link the visualizer view to the media player so that it displays something
        mVisualizerManager = new VisualizerManager(context); //(VisualizerView) findViewById(R.id.visualizerView);
        
        //Send the visualizerContainer to the Renderer
        visualizerRenderer = new VisualizerRenderer(arrayVisualizer);
        mVisualizerManager.addRenderer(visualizerRenderer);
        
        try {
          startPlaying();
      } catch (IllegalStateException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  }
  </code></pre>
  <p>Start playing:</p>
  <pre><code>private void startPlaying () throws IllegalStateException, IOException, UnsupportedOperationException
    {
      
      if(mPlayer != null){
          
            ivPause.setVisibility(View.INVISIBLE);
            ivPlay.setVisibility(View.INVISIBLE);
            ivBuffer.setVisibility(View.VISIBLE);
          
          mVisualizerManager.link(mPlayer);
          
          mPlayer.setOnBufferingUpdateListener(new OnBufferingUpdateListener() {
  
              public void onBufferingUpdate(MediaPlayer mp, int percent) {
                  playSeekBar.setSecondaryProgress(percent);
                  Log.i(&quot;Buffering&quot;, &quot;&quot; + percent);
              }
          });
          
          try {
              mPlayer.setDataSource(theSource);
          } catch (IllegalArgumentException e) {
              Log.d(TAG, &quot;Illegal Argument Exception: &quot;+e);
              e.printStackTrace();
          } catch (IllegalStateException e) {
              Log.d(TAG, &quot;Illegal State Exception: &quot;+e);
              e.printStackTrace();
          } catch (IOException e) {
              Log.d(TAG, &quot;IO Exception: &quot;+e);
              e.printStackTrace();
          }
        
        mPlayer.prepareAsync();
  
        mPlayer.setOnPreparedListener(new OnPreparedListener() {
            public void onPrepared(MediaPlayer mp) {
                ivBuffer.setVisibility(View.INVISIBLE);
                
                bars.setVisibility(View.INVISIBLE);
                visualizerContainer.setVisibility(View.VISIBLE);
                ivInfo.setImageResource(R.drawable.img_radio_info_online);
                ivPause.setVisibility(View.VISIBLE);
                ivPlay.setVisibility(View.INVISIBLE);
                
                //Mute the video if the phone is muted.
                if ((audio.getRingerMode() == AudioManager.RINGER_MODE_SILENT) ||  (audio.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE)) {
                    mp.setVolume(0, 0);
                    
                    Toast toast = Toast.makeText(context, R.string.device_muted, Toast.LENGTH_LONG);
                    toast.show();
                }
                  
                mPlayer.start();
            }
        });
        
      }else{
          Log.d(TAG, &quot;Media player is null.&quot;);
          initialMediaPlayerAndVisualizer();
      }
      
    
    
  }
  </code></pre>
  <p>Stop playing:</p>
  <pre><code>private void stopPlaying()
        {
        bars.setVisibility(View.VISIBLE);
        visualizerContainer.setVisibility(View.INVISIBLE);
  
        ivInfo.setImageResource(R.drawable.img_radio_info_offline);
        
        ivPlay.setVisibility(View.VISIBLE);
        ivPause.setVisibility(View.INVISIBLE);
        
        mPlayer.stop();
        
        mVisualizerManager.release();
        mPlayer.release();
        
        mPlayer = null;
  }
  </code></pre>
  <p>A little logs:</p>
  <pre><code>05-21 16:26:23.600: I/Buffering(3921): 0
  
  05-21 16:26:23.600: I/MediaPlayer(3921): Info (703,156)
  05-21 16:26:23.600: I/MediaPlayer(3921): Info (701,0)
  05-21 16:26:23.610: D/VisualizerRenderer(3921): Render columns
  05-21 16:26:23.715: V/MediaPlayer(3921): message received msg=100, ext1=1, ext2=-110
  05-21 16:26:23.715: E/MediaPlayer(3921): error (1, -110)
  05-21 16:26:23.715: V/MediaPlayer(3921): callback application
  05-21 16:26:23.715: V/MediaPlayer(3921): back from callback
  05-21 16:26:23.725: D/VisualizerRenderer(3921): Render columns
  05-21 16:26:23.725: E/MediaPlayer(3921): Error (1,-110)
  05-21 16:26:23.725: D/MAIN(3921): OnError - Error code: 1 Extra code: -110
  05-21 16:26:23.725: D/Streaming Media(3921): MEDIA_ERROR_UNKNOWN
  05-21 16:26:23.725: D/Streaming Media(3921): Reset media player
  05-21 16:26:23.725: V/MediaPlayer-JNI(3921): reset
  05-21 16:26:23.725: V/MediaPlayer(3921): reset
  05-21 16:26:23.730: D/VisualizerRenderer(3921): Divisions: 9
  05-21 16:26:23.730: D/VisualizerManager(3921): Added te renderer
  05-21 16:26:23.730: V/MediaPlayer-JNI(3921): get_session_id()
  05-21 16:26:23.735: D/VisualizerManager(3921): Media player and visualizer linked
  05-21 16:26:23.735: D/VisualizerManager(3921): Set capture listener
  05-21 16:26:23.735: D/VisualizerManager(3921): Set on visualizer complete listener
  05-21 16:26:23.740: V/MediaPlayer(3921): setVideoSurfaceTexture
  05-21 16:26:23.740: V/MediaPlayer(3921): prepareAsync
  05-21 16:26:25.285: V/MediaPlayer(3921): message received msg=3, ext1=0, ext2=0
  05-21 16:26:25.285: V/MediaPlayer(3921): buffering 0
  05-21 16:26:25.285: V/MediaPlayer(3921): callback application
  05-21 16:26:25.285: V/MediaPlayer(3921): back from callback
  05-21 16:26:25.330: I/Buffering(3921): 0
  05-21 16:26:25.390: V/MediaPlayer(3921): message received msg=3, ext1=0, ext2=0
  05-21 16:26:25.390: V/MediaPlayer(3921): buffering 0
  05-21 16:26:25.390: V/MediaPlayer(3921): callback application
  05-21 16:26:25.390: V/MediaPlayer(3921): back from callback
  05-21 16:26:25.425: I/Buffering(3921): 0
  05-21 16:26:25.490: V/MediaPlayer(3921): message received msg=3, ext1=0, ext2=0
  05-21 16:26:25.490: V/MediaPlayer(3921): buffering 0
  05-21 16:26:25.490: V/MediaPlayer(3921): callback application
  05-21 16:26:25.490: V/MediaPlayer(3921): back from callback
  ...
  
  05-21 16:26:52.585: I/Buffering(3921): 0
  05-21 16:26:53.570: V/MediaPlayer(3921): message received msg=3, ext1=0, ext2=0
  05-21 16:26:53.570: V/MediaPlayer(3921): buffering 0
  05-21 16:26:53.570: V/MediaPlayer(3921): callback application
  05-21 16:26:53.570: V/MediaPlayer(3921): back from callback
  05-21 16:26:53.585: I/Buffering(3921): 0
  05-21 16:26:54.570: V/MediaPlayer(3921): message received msg=3, ext1=0, ext2=0
  05-21 16:26:54.570: V/MediaPlayer(3921): buffering 0
  05-21 16:26:54.570: V/MediaPlayer(3921): callback application
  05-21 16:26:54.570: V/MediaPlayer(3921): back from callback
  05-21 16:26:54.570: V/MediaPlayer(3921): message received msg=200, ext1=702, ext2=0
  05-21 16:26:54.570: W/MediaPlayer(3921): info/warning (702, 0)
  05-21 16:26:54.570: V/MediaPlayer(3921): callback application
  05-21 16:26:54.570: V/MediaPlayer(3921): back from callback
  05-21 16:26:54.590: I/Buffering(3921): 0
  05-21 16:26:54.590: I/MediaPlayer(3921): Info (702,0)
  05-21 16:26:55.575: V/MediaPlayer(3921): message received msg=3, ext1=0, ext2=0
  05-21 16:26:55.575: V/MediaPlayer(3921): buffering 0
  05-21 16:26:55.575: V/MediaPlayer(3921): callback application
  05-21 16:26:55.575: V/MediaPlayer(3921): back from callback
  05-21 16:26:55.575: I/Buffering(3921): 0
  05-21 16:26:56.575: V/MediaPlayer(3921): message received msg=3, ext1=0, ext2=0
  05-21 16:26:56.575: V/MediaPlayer(3921): buffering 0
  05-21 16:26:56.575: V/MediaPlayer(3921): callback application
  05-21 16:26:56.575: V/MediaPlayer(3921): back from callback
  05-21 16:26:56.585: I/Buffering(3921): 0
  05-21 16:26:57.575: V/MediaPlayer(3921): message received msg=3, ext1=0, ext2=0
  05-21 16:26:57.575: V/MediaPlayer(3921): buffering 0
  05-21 16:26:57.575: V/MediaPlayer(3921): callback application
  05-21 16:26:57.575: V/MediaPlayer(3921): back from callback
  05-21 16:26:57.600: I/Buffering(3921): 0
  05-21 16:26:57.930: V/MediaPlayer-JNI(3921): stop
  05-21 16:26:57.930: V/MediaPlayer(3921): stop
  05-21 16:26:57.930: D/VisualizerManager(3921): Released the visualizer
  05-21 16:26:57.930: V/MediaPlayer-JNI(3921): release
  05-21 16:26:57.930: V/MediaPlayer(3921): setListener
  05-21 16:26:57.930: V/MediaPlayer(3921): disconnect
  05-21 16:26:57.935: V/MediaPlayer(3921): destructor
  05-21 16:26:57.935: V/MediaPlayer(3921): disconnect
  </code></pre>