3个步骤:
检查YouTube的源代码(HTML),您将获得这样的链接(http%253A%252F%252Fo-o.preferred.telemar-cnf1.v18.lscache6.c.youtube.com%252Fvideoplayback …) ;
解码url(删除%2B,%25等代码),创建带有以下代码的解码器:http : //www.w3schools.com/tags/ref_urlenpre.asp并使用函数 Uri.depre(url) 替换无效的代码转义的八位位组;
使用代码下载流:
URL u = null; InputStream is = null; try { u = new URL(url); is = u.openStream(); HttpURLConnection huc = (HttpURLConnection)u.openConnection(); //to know the size of video int size = huc.getContentLength(); if(huc != null) { String fileName = "FILE.mp4"; String storagePath = Environment.getExternalStorageDirectory().toString(); File f = new File(storagePath,fileName); FileOutputStream fos = new FileOutputStream(f); byte[] buffer = new byte[1024]; int len1 = 0; if(is != null) { while ((len1 = is.read(buffer)) > 0) { fos.write(buffer,0, len1); } } if(fos != null) { fos.close(); } } } catch (MalformedURLException mue) { mue.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } finally { try { if(is != null) { is.close(); } } catch (IOException ioe) { // just going to ignore this one } }仅此而已,您将在网上找到大部分内容!!!



