thieumao

Get Video Youtube

Apr 16th, 2015
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.67 KB | None | 0 0
  1.     private void getVideo(final String videoID, final String nameVideo){
  2.  
  3.         client.cancelRequests(mContext, true);
  4.         client = new AsyncHttpClient();
  5.    ///      String video_id = "1FJHYqE0RDg";
  6.         String video_id = "";
  7.         String gdata = "http://gdata.youtube.com/feeds/api/videos/";
  8.        
  9.         String urlrequest = "";
  10. //          MyLog.E("url before>>>" + url);
  11. //          if(url.contains("youtube.com")){
  12. //              video_id = url.split("v=")[1];
  13. //              urlrequest = gdata+video_id;
  14. //              urlrequest = url;
  15.             urlrequest = "http://www.youtube.com/watch?v="+videoID;
  16.             client.setUserAgent("Mozilla/5.0 (iPad; CPU OS 6_0_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A523 Safari/8536.25");
  17.             MyLog.E("urlrequest youtube>>>" + urlrequest);
  18. //          }
  19. //          else{
  20. //              urlrequest = String.format(String.valueOf(MyConstans.API_PHIMDETAIL),obj.VideoId,url);
  21. //              MyLog.E("url phimdetail>>>" + urlrequest);
  22. //          }
  23.        
  24.        
  25.         if(myUtil.isInternet(mContext))
  26.         client.get(urlrequest, new AsyncHttpResponseHandler() {
  27.  
  28.             @Override
  29.             public void onStart() {
  30.                 // TODO Auto-generated method stub
  31.                 super.onStart();
  32.            
  33. //                  progressLoading.setVisibility(View.VISIBLE);
  34.             }
  35.  
  36.             @Override
  37.             public void onSuccess(int arg0, String arg1) {
  38.                 // TODO Auto-generated method stub
  39.                 super.onSuccess(arg0, arg1);
  40. //                  progressLoading.setVisibility(View.GONE);
  41. //                  btnPlayPhim.setVisibility(View.VISIBLE);               
  42.                 MyLog.E("phimdetail>>>" + arg1);
  43.                 try {      
  44.                     Intent i = new Intent(mContext,WatchActivity.class );
  45. //                      if(url.contains("youtube.com")){
  46. //                          String rtsp_link = "rtsp:"+ MyUtil.split(MyUtil.split(arg1, "rtsp:")[1], ".3gp")[0] + ".3gp";
  47.                         String rtsp_link =MyUtil.getYoutubeRespond(arg1);
  48.                         MyLog.E("rtsp_link>>>" + rtsp_link);
  49.                         i.putExtra("URLPLAY", rtsp_link);
  50. //                      }
  51. //                      else{
  52. //                          MyLog.E("caption>>>" + arg1);
  53. //                          String strCode = myUtil.getUrlVideo(arg1);                     
  54. //                          i.putExtra("URLPLAY", strCode);                    
  55. //                      }
  56.                     i.putExtra("FILM_NAME", nameVideo);
  57.                     i.putExtra("LINK_SUB", "DM sub");
  58.                     mContext.startActivity(i);
  59.                                                
  60.                 } catch (Exception e) {
  61.                     // TODO: handle exception
  62.                     e.printStackTrace();
  63.                 }
  64.  
  65.             }
  66.  
  67.             @Override
  68.             protected void sendFailureMessage(Throwable arg0, String arg1) {
  69.                 // TODO Auto-generated method stub
  70.                 super.sendFailureMessage(arg0, arg1);
  71.             }
  72.  
  73.         });
  74.         else
  75.             Toast.makeText(mContext, "Lá»—i kết nối mạng", Toast.LENGTH_SHORT).show();
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment