【问题标题】:Record video from VideoView从 VideoView 录制视频
【发布时间】:2012-02-23 20:22:59
【问题描述】:

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

任何帮助表示赞赏

【问题讨论】:

  • 你找到解决方案了吗?

标签: android live-streaming video-recording


【解决方案1】:

您可以使用平台工具并使用以下方式录制视频:

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

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

要将文件拉取到您的计算机....(以下命令,或使用 Android Device Monitor

adb pull /sdcard/demo.mp4

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

【讨论】:

  • 注意:这只会在您希望录制时录制,而不是以编程方式。希望这会有所帮助。
  • 它还会记录整个应用程序的屏幕,而不是我想记录在 VideoView 中播放的视频。
【解决方案2】:

您可以看到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
    }
  }
}

如果服务器不支持下载,你无能为力。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-21
    • 2012-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多