Play Youtube videos in Video View in android

前端 未结 3 774
轮回少年
轮回少年 2021-01-12 10:22

I am developing a youtube player in android. I am getting the rtsp video correct url. But still the video is not playing. Please help to me to find a solution.

Thank

相关标签:
3条回答
  • 2021-01-12 10:41

    Here is another working code

    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>
    
    0 讨论(0)
  • 2021-01-12 10:43

    You can't do that. Use YouTubeAndroidApi for playing YouTube videos.

    0 讨论(0)
  • 2021-01-12 10:52

    There might be many reasons to not play the video,You can test it on other devices also set android:hardwareAccelerated="true" in manifest

    try following listeners to get correct issue

    playerview.setOnPreparedListener(preparelistener);
            playerview.setOnErrorListener(errorlistenr);
            playerview.setOnCompletionListener(completelistener); 
    
    0 讨论(0)
提交回复
热议问题