3

我想通过编程方式从你的视频管中下载视频..现在我可以流式传输这些视频.我在互联网上搜索..但没有完美的解决方案..请针对该问题提出可能的解决方案..谢谢

4

1 回答 1

4

看看这个。我使用此函数从 youtube 视频中提取直接下载链接(它返回一个带有链接的数组)。您需要做的就是使用以下方法获取视频的 html 代码(不是移动版本!):

                 // url = youtube link (e.g. http://www.youtube.com/watch?v=fJ9rUzIMcZQ)
  public String DownloadText(String url) throws IOException{
      String userAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0.1)";
      HttpClient client = new DefaultHttpClient();
      client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, userAgent);

      HttpGet request = new HttpGet(url);
      HttpResponse response = client.execute(request);

      String html = "";
      InputStream in = response.getEntity().getContent();
      BufferedReader reader = new BufferedReader(new InputStreamReader(in));
      StringBuilder str = new StringBuilder();
      String line = null;
      while((line = reader.readLine()) != null)
      {
          str.append(line);
      }
      in.close();
      html = str.toString();

      return html;
    }
于 2013-01-25T13:53:10.173 回答