从VideoView录制视频

时间:2012-02-01 04:57:56

标签: android live-streaming video-recording

目前在直播上做项目,我成功播放了直播视频。现在我的下一个任务是录制正在VideoView中播放的视频。 我曾经搜索过,能够发现捕捉视频但是有表面(相机),但在VideoView中我没有任何表面。

任何帮助表示赞赏

2 个答案:

答案 0 :(得分:3)

您可以看到this链接。简而言之,您的服务器必须支持下载。如果是,您可以尝试以下代码:

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
    }
  }
}

如果服务器不支持下载,则无法执行任何操作。

答案 1 :(得分:3)

您可以使用平台工具和录制视频:

adb shell screenrecord --verbose /sdcard/demo.mp4

将Demo替换为您想要的任何文件名。 这也将放在你的手机上,我相信默认为6分钟。 查看屏幕记录选项。

将文件拉到您的计算机....(以下命令,或使用Android设备监视器

adb pull /sdcard/demo.mp4

我用它来记录应用程序的演示,甚至玩过youtube,并记录了它。 它没有音频,因此这可能是一个主要问题。 但这包含在sdk中,并记录录制时显示的任何屏幕。

相关问题