Get video code from Youtube Link || Youtube video code

 

Want to fetch the Youtube video code from the youtube url to play youtube video?

Integrate youtube video ??? Then its the right place using this method you can fetch the video code out from entire youtube link

 

Android youtube tutorial 

 

 

MVk342D7oMQ   is the video code for the above video url using which you can play youtube video

 

 

public static String getYoutubeVideoId(String youtubeUrl)
 {
 String video_id="";
 if (youtubeUrl != null && youtubeUrl.trim().length() > 0 && youtubeUrl.startsWith("http"))
 {

String expression = "^.*((youtu.be"+ "\\/)" + "|(v\\/)|(\\/u\\/w\\/)|(embed\\/)|(watch\\?))\\??v?=?([^#\\&\\?]*).*"; // var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
 CharSequence input = youtubeUrl;
 Pattern pattern = Pattern.compile(expression,Pattern.CASE_INSENSITIVE);
 Matcher matcher = pattern.matcher(input);
 if (matcher.matches())
 {
 String groupIndex1 = matcher.group(7);
 if(groupIndex1!=null && groupIndex1.length()==11)
 video_id = groupIndex1;
 }
 }
 return video_id;
 }

 

Show Buttons
Hide Buttons
Read previous post:
Android Youtube Player | Your Ultimate Guide to Play Videos in App

  Android Youtube Player : Android Youtube Player, have you ever tried integrating Youtube Player into your app?  yes its...

Close