1. public class YouTubeUtils {
  2.  
  3. public static String 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. }