Play Youtube video while watching video in Android

I am developing a youtube player in android. I get the correct rtsp url. But still the video does not play. Please help me find a solution.

Thanks in advance

Here is my code

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()); } 
+7
android youtube video
source share
3 answers

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(); } //r2---sn-a5m7zu76.c.youtube.com/Ck0LENy73wIaRAnTmlo5oUgpQhMYESARFEgGUg5yZWNvbW1lbmRhdGlvbnIhAWL2kyn64K6aQtkZVJdTxRoO88HsQjpE1a8d1GxQnGDmDA==/0/0/0/video.3gp"); @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> 
+5
source share

You cannot do this. Use YouTubeAndroidApi to play YouTube videos.

+3
source share

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

try following the listeners to get the right problem.

 playerview.setOnPreparedListener(preparelistener); playerview.setOnErrorListener(errorlistenr); playerview.setOnCompletionListener(completelistener); 
+2
source share

All Articles