我正在构建一个需要从Google云端硬盘流视频的Android应用,视频链接就像这样:https:// docs.google.com/file/d / - ID -
我无法获取rtsp,因此它无法在视频中运行视频,并且它不会以mp4或3gp结束...因此我无法像那个:
Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse(" https:// docs.google.com/file/d/--ID--"), "视频/ MP4&#34); 。view.getContext()startActivity(意向);
我可以使用以下代码在webView中运行视频:
webview.getSettings()setJavaScriptEnabled(真)。 。webview.getSettings()setPluginState(WebSettings.PluginState.ON); webview.loadUrl(" https:// docs.google.com/file/d / - ID - ");
webview.setWebChromeClient(new WebChromeClient());
但是视频无法全屏播放,无法暂停并且延迟...
那我该怎么办?无论如何从Google驱动器流式传输视频
答案 0 :(得分:3)
我正在尝试这个,我可以自己找到解决方案
1:确保视频网址为https://drive.google.com/file/d/VIDEO-ID/preview“
2:我从上面的网址下载网页内容并获得直接视频网址:
if let delegate = UIApplication.sharedApplication().delegate as? YOURAPPDELEGATE
//从流输出中获取直接视频网址
public String downloadUrl(String myurl) throws IOException {
InputStream is = null;
try {
URL url = new URL(myurl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000);
conn.setConnectTimeout(15000);
conn.setRequestMethod("GET");
conn.setDoInput(true);
conn.connect();
is = conn.getInputStream();
String contentAsString = readIt(is);
return contentAsString;
} finally {
if (is != null) {
is.close();
}
}
}
//我们需要一个将url解码为正常使用的函数
public String readIt(InputStream stream) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
StringBuilder sb = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
if (line.contains("fmt_stream_map")) {
sb.append(line + "\n");
break;
}
}
reader.close();
String result = decode(sb.toString());
String[] url = result.split("\\|");
return url[1];
}
现在我使用了三个函数后,我可以得到一个直接的视频网址,它由public String decode(String in) {
String working = in;
int index;
index = working.indexOf("\\u");
while (index > -1) {
int length = working.length();
if (index > (length - 6)) break;
int numStart = index + 2;
int numFinish = numStart + 4;
String substring = working.substring(numStart, numFinish);
int number = Integer.parseInt(substring, 16);
String stringStart = working.substring(0, index);
String stringEnd = working.substring(numFinish);
working = stringStart + ((char) number) + stringEnd;
index = working.indexOf("\\u");
}
return working;
}
作为字符串返回,我可以用它来解析为VideoView。