在Android视频视图中播放Youtube视频

前端之家收集整理的这篇文章主要介绍了在Android视频视图中播放Youtube视频前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在 android中开发了一个youtube播放器.我正在获取rtsp视频正确的网址.但仍然没有播放视频.请帮我找到解决方案.

提前致谢

这是我的代码

String youtubeURL="rtsp://v6.cache4.c.youtube.com/CigLENy73wIaHwmh5W2TKCuN2RMYDSANFEgGUgx1c2VyX3VwbG9hZHMM/0/0/0/video.3gp";
  @Override
protected void onCreate(Bundle savedInstanceState)
{
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_online_video_player);

       videoView = (VideoView) findViewById(R.id.video_View);

       progressDialog = ProgressDialog.show(OnlineVideoPlayer.this,"","Buffering video...",true);
       progressDialog.setCancelable(false);


       PlayVideo();
}

private void PlayVideo()
{
       try {
           final VideoView videoView =(VideoView)findViewById(R.id.video_View);
     //1   //mediaController = new MediaController(Splashscreen.this);
     //2   //mediaController.setAnchorView(videoView);
           // Set video link (mp4 format )
           Uri video = Uri.parse(youtubeURL);
           //videoView.setMediaController(mediaController);
           videoView.setVideoURI(video);
           videoView.setOnPreparedListener(new OnPreparedListener() {
               public void onPrepared(MediaPlayer mp) {
                   progressDialog.dismiss();
                  videoView.start();
               }
           });

        }catch(Exception e){
             progressDialog.dismiss();
            System.out.println("Video Play Error :"+e.getMessage());
        }

解决方法

这是另一个工作代码

MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_video_view);

    VideoView videoView =(VideoView)findViewById(R.id.videoView);
    MediaController mediaController= new MediaController(this);
    mediaController.setAnchorView(videoView);
    Uri uri=Uri.parse("rtsp://r2---sn-a5m7zu76.c.youtube.com/Ck0LENy73wIaRAnTmlo5oUgpQhMYESARFEgGUg5yZWNvbW1lbmRhdGlvbnIhAWL2kyn64K6aQtkZVJdTxRoO88HsQjpE1a8d1GxQnGDmDA==/0/0/0/video.3gp");
    videoView.setMediaController(mediaController);
    videoView.setVideoURI(uri);
    videoView.requestFocus();

    videoView.start();


}

activity_video_view.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<VideoView android:id="@+id/videoView"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"/>
</LinearLayout>
原文链接:https://www.f2er.com/android/316070.html

猜你在找的Android相关文章