【问题标题】:android URL stream cannot get whole dataandroid URL流无法获取整个数据
【发布时间】:2014-02-01 01:56:24
【问题描述】:

我正在尝试使用此获取 youtube 下载链接

String data = getURL("http://www.youtube.com/get_video_info?video_id=" + id);

但它总是返回一部分数据。数据的结尾像“...”例如,

expire%253D1391242316%2526ms%253Dau%2526fexp%253D900356%25252C902546%25252C936910%252...

我用过这段代码

public String getURL(String s){
    InputStream is = null;  

    try{

        URL r = new URL(s);
        URLConnection rc = r.openConnection();

        DataInputStream dis = new DataInputStream(rc.getInputStream());

        List<Byte> l = new ArrayList<Byte>();

        while(true){
            try{
                l.add(dis.readByte());
            }catch(Exception e){
                break;
            }
        }

        byte[] b = new byte[l.size()];
        for(int i = 0; i < l.size(); i++){
            b[i] = l.get(i);
        }

        return new String(b,"UTF-8");


    }catch(Exception e){

        e.printStackTrace();
        return null;

    }
}

有没有人为什么这不能得到完整的数据? 如果我只是通过这个url使用chrome就可以下载它

http://www.youtube.com/get_video_info?video_id=itGNQbJwRSk

它下载整个文件。但流媒体不能。

【问题讨论】:

    标签: android youtube urlstream


    【解决方案1】:

    我是愚蠢的!这只是调试窗口值。

    我记录了字符串长度,发现它与文件总长度相同。

    【讨论】:

      猜你喜欢
      • 2013-07-14
      • 1970-01-01
      • 2014-05-28
      • 1970-01-01
      • 2013-07-03
      • 1970-01-01
      • 2014-02-23
      • 2013-01-19
      • 2019-05-29
      相关资源
      最近更新 更多