title: RTSP live stream on Android
body: <p>I try to make a live stream on Android. I tried lots of ways, but none of them
  worked. How can I do it?</p>
  
  <p>This is example of RTSP:</p>
  
  <pre><code>mMediaPlayer = new MediaPlayer();
  mMediaPlayer.setDataSource(KralStream.getTvStreamUrl().toString());
  mMediaPlayer.setDisplay(holder);
  mMediaPlayer.prepareAsync();
  mMediaPlayer.setOnBufferingUpdateListener(this);
  mMediaPlayer.setOnCompletionListener(this);
  mMediaPlayer.setOnPreparedListener(this);
  mMediaPlayer.setOnVideoSizeChangedListener(this);
  mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
  mMediaPlayer.setLooping(true);
  </code></pre>
  
  <blockquote>
    <p>Exeption :05-26 10:22:46.186: <br/>
    ERROR/MediaPlayerService(10157): <br/>
    create PVPlayer 05-26 10:23:06.382: <br/>
    ERROR/PlayerDriver(10157): Command <br/>
    PLAYER_INIT completed with an error or <br/>
    info -1 05-26 10:23:06.382: <br/>
    ERROR/MediaPlayer(23800): error (1, <br/>
    -1) 05-26 10:23:06.382: ERROR/MediaPlayer(23800): Error (1,-1) <br/></p>
  </blockquote>
  
  <p>RTSP:</p>
  
  <pre><code>VideoView videoView = (VideoView)findViewById(R.id.videoView1);
  Uri uri = Uri.parse("rtsp://strm-3.tr.medianova.tv/rkraltv/rkraltv");
  videoView.setVideoURI(uri);
  videoView.start();
  </code></pre>
  
  <p>It gives this message:</p>
  
  <blockquote>
    <p>"Sorry, this video <br/>
    cannot ve played." Exeptions;05-26 <br/>
    10:40:08.979: <br/>
    ERROR/MediaPlayerService(10157): <br/>
    create PVPlayer 05-26 10:40:09.188: <br/>
    INFO/ActivityManager(10163): Displayed <br/>
    activity <br/>
    com.giantrabbit.nagare/.KralTvNow: 433 <br/>
    ms (total 433 ms) 05-26 10:40:11.702: <br/>
    WARN/PowerManagerService(10163): Timer <br/>
    0x3->0x3|0x1 05-26 10:40:29.061: <br/>
    WARN/MediaPlayer(24284): info/warning <br/>
    (1, 26) 05-26 10:40:29.061: <br/>
    INFO/MediaPlayer(24284): Info (1,26) <br/>
    05-26 10:40:29.100: <br/>
    ERROR/PlayerDriver(10157): Command <br/>
    PLAYER_INIT completed with an error or <br/>
    info -1 05-26 10:40:29.104: <br/>
    ERROR/MediaPlayer(24284): error (1, <br/>
    -1) 05-26 10:40:29.108: ERROR/MediaPlayer(24284): Error (1,-1) <br/></p>
  </blockquote>
  
  <p>RTSP:</p>
  
  <pre><code>mPreview = (SurfaceView) findViewById(R.id.surface);
  holder = mPreview.getHolder();
  holder.addCallback(this);
  holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
  extras = getIntent().getExtras();
  
  public void play() {
      try {
          Uri video = KralStream.getTvStreamUrl();
          Toast.makeText(this, video.toString(), Toast.LENGTH_SHORT).show();
          mMediaPlayer = new MediaPlayer();
          mMediaPlayer.setDataSource(path);
          mMediaPlayer.setDisplay(holder);
          mMediaPlayer.prepare();
          mMediaPlayer.setOnBufferingUpdateListener(this);
          mMediaPlayer.setOnCompletionListener(this);
          mMediaPlayer.setOnPreparedListener(this);
          mMediaPlayer.setOnVideoSizeChangedListener(this);
          mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
      }
      catch (Exception e) {
          Log.e(TAG, "error: " + e.getMessage(), e);
      }
  }
  </code></pre>
  
  <p>Exeption:</p>
  
  <blockquote>
    <p>05-26 10:36:57.589: <br/>
    ERROR/MediaPlayerService(10157): <br/>
    create PVPlayer 05-26 10:37:20.542: <br/>
    ERROR/PlayerDriver(10157): Command <br/>
    PLAYER_INIT completed with an error or <br/>
    info -1 05-26 10:37:20.542: <br/>
    ERROR/MediaPlayer(24240): error (1, <br/>
    -1) 05-26 10:37:20.565: WARN/PlayerDriver(10157): <br/>
    PVMFInfoErrorHandlingComplete 05-26 <br/>
    10:37:20.682: <br/>
    ERROR/MediaPlayerDemo(24240): error: <br/>
    Prepare failed.: status=0x1 05-26 <br/>
    10:37:20.682: <br/>
    ERROR/MediaPlayerDemo(24240): <br/>
    java.io.IOException: Prepare failed.: <br/>
    status=0x1 05-26 10:37:20.682: <br/>
    ERROR/MediaPlayerDemo(24240): at <br/>
    android.media.MediaPlayer.prepare(Native <br/>
    Method) 05-26 10:37:20.682: <br/>
    ERROR/MediaPlayerDemo(24240): at <br/>
    com.giantrabbit.nagare.KralTvNow.play(KralTvNow.java:162) <br/>
    05-26 10:37:20.682: <br/>
    ERROR/MediaPlayerDemo(24240): at <br/>
    com.giantrabbit.nagare.KralTvNow.surfaceCreated(KralTvNow.java:215) <br/>
    05-26 10:37:20.682: <br/>
    ERROR/MediaPlayerDemo(24240): at <br/>
    android.view.SurfaceView.updateWindow(SurfaceView.java:536) <br/>
    05-26 10:37:20.682: <br/>
    ERROR/MediaPlayerDemo(24240): at <br/>
    android.view.SurfaceView.dispatchDraw(SurfaceView.java:339) <br/>
    05-26 10:37:20.682: <br/>
    ERROR/MediaPlayerDemo(24240): at <br/>
    android.view.ViewGroup.drawChild(ViewGroup.java:1638) <br/>
    05-26 10:37:20.682: <br/>
    ERROR/MediaPlayerDemo(24240): at <br/>
    android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367) <br/>
    05-26 10:37:20.682: <br/>
    ERROR/MediaPlayerDemo(24240): at <br/>
    android.view.ViewGroup.drawChild(ViewGroup.java:1638) <br/>
    05-26 10:37:20.682: <br/>
    ERROR/MediaPlayerDemo(24240): at <br/>
    android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367) <br/>
    05-26 10:37:20.682: <br/>
    ERROR/MediaPlayerDemo(24240): at <br/>
    android.view.View.draw(View.java:6796) <br/>
    05-26 10:37:20.682: <br/>
    ERROR/MediaPlayerDemo(24240): at <br/>
    android.widget.FrameLayout.draw(FrameLayout.java:352) <br/>
    05-26 10:37:20.682: <br/>
    ERROR/MediaPlayerDemo(24240): at <br/>
    android.view.ViewGroup.drawChild(ViewGroup.java:1640) <br/>
    05-26 10:37:20.682: <br/>
    ERROR/MediaPlayerDemo(24240): at <br/>
    android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367) <br/>
    05-26 10:37:20.682: <br/>
    ERROR/MediaPlayerDemo(24240): at <br/>
    android.view.View.draw(View.java:6796) <br/>
    05-26 10:37:20.682: <br/>
    ERROR/MediaPlayerDemo(24240): at <br/>
    android.widget.FrameLayout.draw(FrameLayout.java:352) <br/>
    05-26 10:37:20.682: <br/>
    ERROR/MediaPlayerDemo(24240): at <br/>
    com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1894) <br/>
    05-26 10:37:20.682: <br/>
    ERROR/MediaPlayerDemo(24240): at <br/>
    android.view.ViewRoot.draw(ViewRoot.java:1407) <br/>
    05-26 10:37:20.682: <br/>
    ERROR/MediaPlayerDemo(24240): at <br/>
    android.view.ViewRoot.performTraversals(ViewRoot.java:1163) <br/>
    05-26 10:37:20.682: <br/>
    ERROR/MediaPlayerDemo(24240): at <br/>
    android.view.ViewRoot.handleMessage(ViewRoot.java:1727) <br/>
    05-26 10:37:20.682: <br/>
    ERROR/MediaPlayerDemo(24240): at <br/>
    android.os.Handler.dispatchMessage(Handler.java:99) <br/>
    05-26 10:37:20.682: <br/>
    ERROR/MediaPlayerDemo(24240): at <br/>
    android.os.Looper.loop(Looper.java:123) <br/>
    05-26 10:37:20.682: <br/>
    ERROR/MediaPlayerDemo(24240): at <br/>
    android.app.ActivityThread.main(ActivityThread.java:4627) <br/>
    05-26 10:37:20.682: <br/>
    ERROR/MediaPlayerDemo(24240): at <br/>
    java.lang.reflect.Method.invokeNative(Native <br/>
    Method) 05-26 10:37:20.682: <br/>
    ERROR/MediaPlayerDemo(24240): at <br/>
    java.lang.reflect.Method.invoke(Method.java:521) <br/>
    05-26 10:37:20.682: <br/>
    ERROR/MediaPlayerDemo(24240): at <br/>
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:871) <br/>
    05-26 10:37:20.682: <br/>
    ERROR/MediaPlayerDemo(24240): at <br/>
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629) <br/>
    05-26 10:37:20.682: <br/>
    ERROR/MediaPlayerDemo(24240): at <br/>
    dalvik.system.NativeStart.main(Native <br/>
    Method) 05-26 10:37:20.737: <br/>
    INFO/MediaPlayer(24240): Info (1,26) <br/>
    05-26 10:37:20.737: <br/>
    ERROR/MediaPlayer(24240): Error (1,-1) <br/>
    05-26 10:37:20.868: <br/>
    INFO/ActivityManager(10163): Displayed <br/>
    activity <br/>
    com.giantrabbit.nagare/.KralTvNow: <br/>
    25864 ms (total 25864 ms) 05-26 <br/>
    10:37:23.777: <br/>
    WARN/PowerManagerService(10163): Timer <br/>
    0x3->0x3|0x1 <br/></p>
  </blockquote>
  
  <p>This is an example of HTTP:</p>
  
  <pre><code>mMediaPlayer = new MediaPlayer();
  mMediaPlayer.setDataSource("http://ikral.garantisistem.com:1935/ikral/smil:kral.smil/playlist.m3u8");
  mMediaPlayer.setDisplay(holder);
  mMediaPlayer.prepareAsync();
  mMediaPlayer.setOnBufferingUpdateListener(this);
  mMediaPlayer.setOnCompletionListener(this);
  mMediaPlayer.setOnPreparedListener(this);
  mMediaPlayer.setOnVideoSizeChangedListener(this);
  mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
  mMediaPlayer.setLooping(true);
  </code></pre>
  
  <p>Exception:</p>
  
  <blockquote>
    <p>05-26 10:16:24.276: <br/>
    ERROR/MediaPlayerService(10157): <br/>
    create PVPlayer 05-26 10:16:24.292: <br/>
    ERROR/(10157): IIIIIII Inside <br/>
    Constructor of <br/>
    PVMFMemoryBufferWriteDataStreamImpl <br/>
    05-26 10:16:24.346: <br/>
    INFO/PlayerDriver(10157): buffering <br/>
    (100) 05-26 10:16:24.346: <br/>
    ERROR/(10157): IIIIIII Inside <br/>
    Constructor of <br/>
    PVMFMemoryBufferReadDataStreamImpl <br/>
    05-26 10:16:24.346: ERROR/(10157): <br/>
    IIIIIII Inside Constructor of <br/>
    PVMFMemoryBufferReadDataStreamImpl <br/>
    05-26 10:16:24.346: ERROR/(10157): <br/>
    IIIIIII Inside Constructor of <br/>
    PVMFMemoryBufferReadDataStreamImpl <br/>
    05-26 10:16:24.346: ERROR/(10157): <br/>
    IIIIIII Inside Constructor of <br/>
    PVMFMemoryBufferReadDataStreamImpl <br/>
    05-26 10:16:24.346: ERROR/(10157): <br/>
    IIIIIII Inside Constructor of <br/>
    PVMFMemoryBufferReadDataStreamImpl <br/>
    05-26 10:16:24.346: ERROR/(10157): <br/>
    IIIIIII Inside Constructor of <br/>
    PVMFMemoryBufferReadDataStreamImpl <br/>
    05-26 10:16:24.346: ERROR/(10157): <br/>
    IIIIIII Inside Constructor of <br/>
    PVMFMemoryBufferReadDataStreamImpl <br/>
    05-26 10:16:24.346: ERROR/(10157): <br/>
    IIIIIII Inside Constructor of <br/>
    PVMFMemoryBufferReadDataStreamImpl <br/>
    05-26 10:16:24.346: ERROR/(10157): <br/>
    IIIIIII Inside Constructor of <br/>
    PVMFMemoryBufferReadDataStreamImpl <br/>
    05-26 10:16:24.346: ERROR/(10157): <br/>
    IIIIIII Inside Constructor of <br/>
    PVMFMemoryBufferReadDataStreamImpl <br/>
    05-26 10:16:24.346: ERROR/(10157): <br/>
    IIIIIII Inside Constructor of <br/>
    PVMFMemoryBufferReadDataStreamImpl <br/>
    05-26 10:16:24.346: ERROR/(10157): <br/>
    IIIIIII Inside Constructor of <br/>
    PVMFMemoryBufferReadDataStreamImpl <br/>
    05-26 10:16:24.350: <br/>
    WARN/MediaPlayer(23736): info/warning <br/>
    (1, 26) 05-26 10:16:24.354: <br/>
    ERROR/PlayerDriver(10157): Command <br/>
    PLAYER_INIT completed with an error or <br/>
    info -10 05-26 10:16:24.354: <br/>
    ERROR/MediaPlayer(23736): error (-10, <br/>
    -10) 05-26 10:16:24.354: WARN/PlayerDriver(10157): <br/>
    PVMFInfoErrorHandlingComplete 05-26 <br/>
    10:16:24.393: INFO/MediaPlayer(23736): <br/>
    Info (1,26) 05-26 10:16:24.393: <br/>
    ERROR/MediaPlayer(23736): Error <br/>
    (-10,-10) <br/></p>
  </blockquote>
  
  <p>HTTP:</p>
  
  <pre><code>VideoView videoView = (VideoView)findViewById(R.id.videoView1);
  Uri uri = Uri.parse("http://ikral.garantisistem.com:1935/ikral/smil:kral.smil/playlist.m3u8");
  videoView.setVideoURI(uri);
  videoView.start();
  </code></pre>
  
  <p>It gives the message:</p>
  
  <blockquote>
    <p>"Sorry, this video cannot ve played."</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/pjSeu.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pjSeu.jpg" alt="enter image description here"></a></p>