如何在Android Mediaplayer中播放Youtube视频

时间:2017-07-23 20:19:01

标签: android youtube android-videoview

我需要在我的android项目中播放Youtube视频。

我在哪里使用MediaPlayer而不是YoutubePlayer Api。 如何从视频ID或此类链接获得RTSP链接..?

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");

1 个答案:

答案 0 :(得分:0)

Media Player用于播放声音,而不是视频。 播放视频时,您可以尝试使用SurfaceView或VideoView

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

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