How to Play RTSP Video in Android?

Deepanker Chaudhary picture Deepanker Chaudhary · Oct 12, 2012 · Viewed 7.6k times · Source

I want to play Youtube Video on VideoView . I have searched very much & find that VideoView Support rtsp URL Video . But I am getting error: My android device is 2.3.5 & using Wifi. My VideoView Code is:

  final VideoView videoView = (VideoView) findViewById(R.id.VideoView);
        Button youtube=(Button)findViewById(R.id.button1);
       final  MediaController mediaController = new MediaController(this);
        mediaController.setScrollBarStyle(DEFAULT_KEYS_DISABLE);
        mediaController.setPressed(true);
         mediaController.setAnchorView(videoView);
        Uri video = Uri.parse("rtsp://v3.cache7.c.youtube.com/CiILENy73wIaGQlOCTh0GvUeYRMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp");
       // Uri video = Uri.parse(getUrlVideoRTSP("http://gdata.youtube.com/feeds/api/users/mashable/uploads?&v=2"));
        videoView.setMediaController(mediaController);
        videoView.setVideoURI(video);
        videoView.requestFocus();
        videoView.start();

My LogCat Error is:

10-12 11:56:50.369: D/WindowManagerImpl(6880): addView, new view, mViews[0]: com.android.internal.policy.impl.PhoneWindow$DecorView@4055c4e0

10-12 11:56:50.430: I/AudioSystem(6880): getting audio flinger

10-12 11:56:50.430: I/AudioSystem(6880): returning new audio session id

10-12 11:56:50.430: D/MediaPlayer(6880): setDataSource(Context context, rtsp://v3.cache7.c.youtube.com/CiILENy73wIaGQlOCTh0GvUeYRMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp, Map<String, String> headers) in

10-12 11:56:50.460: I/MediaPlayer(6880): skip setting (httpproxyip,null)

10-12 11:56:50.460: I/MediaPlayer(6880): skip setting (httpproxyport,null)

10-12 11:56:50.460: I/MediaPlayer(6880): skip setting (rtspproxyip,null) 

10-12 11:56:50.460: I/MediaPlayer(6880): skip setting (rtspproxyport,null) 

10-12 11:56:50.460: I/MediaPlayer(6880): add setting (minudpport,1024)

10-12 11:56:50.460: I/MediaPlayer(6880): add setting (maxudpport,65535)

10-12 11:56:50.460: I/MediaPlayer(6880): add setting (buffertime,7)

10-12 11:56:50.460: I/MediaPlayer(6880): add setting (rtsptimeout,25000)

10-12 11:56:50.460: I/MediaPlayer(6880): add setting (rtptimeout,25000)

10-12 11:56:50.460: I/MediaPlayer(6880): add setting (rtcpreportinterval,3000)

10-12 11:56:50.460: I/MediaPlayer(6880): add setting (rtspkeepaliveinterval,35000)
10-12 11:56:50.460: D/MediaPlayer(6880): Couldn't open file on client side, trying server side

10-12 11:56:50.470: I/MediaPlayer(6880): disable CIQ

10-12 11:56:50.470: D/MediaPlayer(6880): setDataSource(Context context, rtsp://v3.cache7.c.youtube.com/CiILENy73wIaGQlOCTh0GvUeYRMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp, Map<String, String> headers) out

10-12 11:57:20.589: W/MediaPlayer(6880): info/warning (34355, 3000)

10-12 11:57:20.589: I/MediaPlayer(6880): Info (34355,3000)

10-12 11:57:20.599: E/MediaPlayer(6880): error (1, -1003)

10-12 11:57:20.599: E/MediaPlayer(6880): Error (1,-1003)

10-12 11:57:20.599: D/VideoView(6880): Error: 1,-1003

Answer

Hardik Joshi picture Hardik Joshi · Oct 12, 2012

First you have to get videos from your YOutube Channel. For this following Example will help you.

See My answer Here. it will give you perfect idea about this.

Also for playing video in videoview you need rtsp format of your video.

You can convert your url in rtsp format i create function for that which is HERE.