How to play YouTube videos on Android?

I have a VideoView and I set the youtube video URI and install android.permission.INTERNET , but I got this message when I want to play the video .. "you cannot play the video"

this code snippet for video player

  mVideoView = (VideoView) findViewById(R.id.skillVideo); mVideoView.setVideoURI(Uri.parse("http://www.youtube.com/watch?v=1_pryg5HFYY")); mVideoView.setMediaController(new MediaController(this)); mVideoView.requestFocus(); 

and this is the VideoView in the xml layout file:

 .... <VideoView android:id="@+id/skillVideo" android:layout_width="wrap_content" android:layout_height="200dp"></VideoView> .... 
+2
android
Jul 02 2018-11-11T00:
source share
2 answers

Here's what I did in this code, I removed MediaControllers from the user interface and started my YouTube video stream that rtsp threw, and in my layout there is a basic VideoView with my necessary button. You can see it in real action here on Android.

Markethttps: //market.android.com/details? id = com.sbrecords & feature = search_result #? t = W251bGwsMSwyLDEsImNvbS5zYnJlY29yZHMiXQ .. video_url = "rtsp: //v7.cache3.c.youtube.com/CjgLENy73wIaLwkeUryQ8ZkCqRMYJCAkBIJBj2JBJ2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2J2_J2J2_J2]]

  try { final VideoView videoView =(VideoView)findViewById(R.id.videoView1); //1 //mediaController = new MediaController(Splashscreen.this); //2 //mediaController.setAnchorView(videoView); // Set video link (mp4 format ) Uri video = Uri.parse(video_url); //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()); } // Thread to waste time while displaying splash screen Thread SplashThread = new Thread() { @Override public void run() { try { synchronized (this) { // Wait given period of time wait(7450000); } } catch (InterruptedException ex) { } finish(); 
+1
Feb 14 2018-12-12T00:
source share
β€” -

@Adham, you thought about using the YouTube API for Android. They have excellent viewing, which gives you many opportunities to control and listen to events on video. I recently published a tutorial on using the API, if it can meet your needs, check here

-one
Jul 25 '13 at
source share



All Articles