栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在Java,Android上从Youtube下载视频的代码

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在Java,Android上从Youtube下载视频的代码

3个步骤:

  1. 检查YouTube的源代码(HTML),您将获得这样的链接(http%253A%252F%252Fo-o.preferred.telemar-cnf1.v18.lscache6.c.youtube.com%252Fvideoplayback …) ;

  2. 解码url(删除%2B,%25等代码),创建带有以下代码的解码器:http : //www.w3schools.com/tags/ref_urlenpre.asp并使用函数 Uri.depre(url) 替换无效的代码转义的八位位组;

  3. 使用代码下载流:

        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        }    }

仅此而已,您将在网上找到大部分内容!!!



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/486458.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号