如何捕捉视频的URL中的Android /记录剪辑并保存到手机
在Android的,是它可以记录短片(例如:一个任意5-10秒的视频)的视频网址(例如:的 http://www.test.com/video.mp4 )?
In Android, is it possible to record a short clip (ex: an arbitrary 5-10 seconds in the video) from a Video URL (ex: http://www.test.com/video.mp4)?
例如,我想流中的活动的视频(来自URL),并允许捕捉/从中录制短片的能力。或许,允许用户记录从视频的任意开始/结束时间。如果是这样,有一个API来做到这一点?如果没有,是否有一个Android库来支持这一点?
For example, I'd like to stream a video (from url) in an Activity and allow the ability to capture/record a short clip from it. Perhaps, allow the user to record an arbitrary Start/End time from the video. If so, is there an API to accomplish this? If not, is there an Android library to support this?
请提供样品code解决方案这一点。
Please provide a sample code solution for this.
您可以看到this链接。总之你的服务器必须支持下载。如果是的话,你可以试试下面的code:
You can see this link. In short your server has to support downloading. If it does, you can try the following code:
private final int TIMEOUT_CONNECTION = 5000; //5sec
private final int TIMEOUT_SOCKET = 30000; //30sec
private final int BUFFER_SIZE = 1024 * 5; // 5MB
private final int TIMEOUT_CONNECTION = 5000; //5sec
private final int TIMEOUT_SOCKET = 30000; //30sec
private final int BUFFER_SIZE = 1024 * 5; // 5MB
try {
URL url = new URL("http://....");
//Open a connection to that URL.
URLConnection ucon = url.openConnection();
ucon.setReadTimeout(TIMEOUT_CONNECTION);
ucon.setConnectTimeout(TIMEOUT_SOCKET);
// Define InputStreams to read from the URLConnection.
// uses 5KB download buffer
InputStream is = ucon.getInputStream();
BufferedInputStream in = new BufferedInputStream(is, BUFFER_SIZE);
FileOutputStream out = new FileOutputStream(file);
byte[] buff = new byte[BUFFER_SIZE];
int len = 0;
while ((len = in.read(buff)) != -1)
{
out.write(buff,0,len);
}
} catch (IOException ioe) {
// Handle the error
} finally {
if(in != null) {
try {
in.close();
} catch (Exception e) {
// Nothing you can do
}
}
if(out != null) {
try {
out.flush();
out.close();
} catch (Exception e) {
// Nothing you can do
}
}
}
如果服务器不支持下载,还有什么可以做。
If the server doesn't support downloading, there is nothing you can do.