如何捕捉视频的URL中的Andr​​oid /记录剪辑并保存到手机 [英] How to capture/record clip from Video URL in Android and save to phone

查看:430
本文介绍了如何捕捉视频的URL中的Andr​​oid /记录剪辑并保存到手机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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.

推荐答案

您可以看到<一href="http://stackoverflow.com/questions/24569604/how-can-i-record-the-currently-live-video-stream-playing-in-media-player">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.

这篇关于如何捕捉视频的URL中的Andr​​oid /记录剪辑并保存到手机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆