1

I need to play a Youtube video in my android project.

Where i am using MediaPlayer not YoutubePlayer Api. How can i get RTSP link from a video id or this type o f link..?

private MediaPlayer mMediaPlayer = null;
mMediaPlayer = new MediaPlayer();

mMediaPlayer.setDataSource("https://r2---sn-gvcp5mp5u5-jb2e.googlevideo.com/videoplayback?sparams=dur%2Cei%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Cratebypass%2Crequiressl%2Csource%2Cexpire&ipbits=0&ei=fcp0WYamOYbcogOjyLa4Dw&pl=24&ratebypass=yes&requiressl=yes&mime=video%2Fmp4&expire=1500847838&initcwndbps=173750&mn=sn-gvcp5mp5u5-jb2e&itag=22&signature=C127F7D775420D4B6B212D179A8646B37050E11E.522C99F874D1F96CD0AC0F32B3237D748F5412FB&mm=31&mt=1500825996&id=o-AGZK-vdS6Nn30ULgrBRUI6BxRirCwJh_qdrglkQzAioR&dur=46.393&mv=m&source=youtube&ms=au&lmt=1472804597021430&ip=202.134.9.129&key=yt6");
UmarZaii
  • 1,355
  • 1
  • 17
  • 26
tanvirHaque
  • 41
  • 1
  • 7

1 Answers1

-2

Media Player is using for playing sound, not video. for playing video you can try to work with SurfaceView or VideoView

https://developer.android.com/reference/android/view/SurfaceView.html

or

https://developer.android.com/reference/android/widget/VideoView.html

Yoni
  • 1,346
  • 3
  • 16
  • 38
  • 1
    Are you sure that only sound can be played? "MediaPlayer class can be used to control playback of audio/video files and streams. An example on how to use the methods in this class can be found in VideoView." https://developer.android.com/reference/android/media/MediaPlayer.html – Andrii Lisun Jul 23 '17 at 20:25
  • yes, I'm sure. SurfaceView is handling the video and Media Player handle the sound and they work together. – Yoni Jul 23 '17 at 20:29
  • As far as I understood. MediaPlayer handles video playback and renders to SurfaceView. – Andrii Lisun Jul 23 '17 at 20:32
  • 1
    Correct. and here a good tutorial: http://www.java2s.com/Code/Android/Media/UsingMediaPlayertoplayVideoandAudio.htm – Yoni Jul 23 '17 at 20:33
  • Downvoted for not doing basic research. MediaPlayer has been able to play video since the time it was created: https://developer.android.com/guide/topics/media/mediaplayer – Johann Apr 25 '21 at 09:56