谁能告诉我如何编码/解码(在android中) youtube URL,这是间接的直接URL,以便从Youtube下载视频??我尝试了各种可能的方法来转换实际的间接URL,并对它们进行编码,以提供另一个包含十六进制值的URL。但是这个方法不起作用,因为我不能使用我的下载管理器类解析URL来下载视频。感谢所有在这个论坛上帮助像我这样的初学者的开发天才。提前感谢那些给我提供解决方案的人。
PS:这只是个人使用,而不是商业用途。另外,我这么做只是出于好奇。
发布于 2014-08-26 14:47:01
3个步骤:
步骤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
}
}https://stackoverflow.com/questions/25499544
复制相似问题