Quantcast
Channel: Developer Feed - Snippet
Viewing all articles
Browse latest Browse all 178

How to Youtube videoID from the URL in Android?

$
0
0
  1. publicclass YouTubeUtils {
  2.  
  3. publicstaticString getVideoIdFromUrl(String url){
  4.  
  5.  Log.d("getVideoIdFromUrl : "+ url);
  6.  String vid =null;
  7.  try{
  8.    // <a href="http://www.youtube.com/watch?v=Vr_Bq_GWyuU
  9. " title="http://www.youtube.com/watch?v=Vr_Bq_GWyuU
  10. ">http://www.youtube.com/watch?v=Vr_Bq_GWyuU
  11. </a>    int vindex = url.indexOf("v=");
  12.    int ampIndex = url.indexOf("&", vindex);
  13.  
  14.   Log.d("v= not found " + vindex);
  15.   if (ampIndex < 0) {
  16.         Log.d("& not found " + ampIndex);
  17.                 vid = url.substring(vindex + 2);
  18.   } else {
  19.         Log.d("& found at " + ampIndex);
  20.         vid = url.substring(vindex + 2, ampIndex);
  21.   }
  22. } catch (Exception e) {
  23.   Log.e("Failed to get the vid " + e.getMessage(), e);
  24. }
  25.  
  26.  Log.d("vid :" + vid);
  27.  
  28.  return vid;
  29.  
  30. }
  31.  
  32. }

Viewing all articles
Browse latest Browse all 178

Trending Articles