- publicclass YouTubeUtils {
- publicstaticString getVideoIdFromUrl(String url){
- Log.d("getVideoIdFromUrl : "+ url);
- String vid =null;
- try{
- // <a href="http://www.youtube.com/watch?v=Vr_Bq_GWyuU
- " title="http://www.youtube.com/watch?v=Vr_Bq_GWyuU
- ">http://www.youtube.com/watch?v=Vr_Bq_GWyuU
- </a> int vindex = url.indexOf("v=");
- int ampIndex = url.indexOf("&", vindex);
- Log.d("v= not found " + vindex);
- if (ampIndex < 0) {
- Log.d("& not found " + ampIndex);
- vid = url.substring(vindex + 2);
- } else {
- Log.d("& found at " + ampIndex);
- vid = url.substring(vindex + 2, ampIndex);
- }
- } catch (Exception e) {
- Log.e("Failed to get the vid " + e.getMessage(), e);
- }
- Log.d("vid :" + vid);
- return vid;
- }
- }
↧
How to Youtube videoID from the URL in Android?
↧