Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Record video from VideoView

Currently doing project on live Streaming, and I succeed to play live video. Now my next task is to record the video which is playing in VideoView. I had searched, able to found capturing video but with surface(camera) but here in VideoView I am not having any surface.

any help appreciated

like image 339
Mohammed Azharuddin Shaikh Avatar asked Feb 01 '12 04:02

Mohammed Azharuddin Shaikh


2 Answers

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.

like image 68
Ahmad Nawaz Avatar answered Nov 09 '22 03:11

Ahmad Nawaz


You can use platform-tools and record video using:

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

Replace Demo with whatever file name you want. Also this will be placed on your phone, and defaults to 6 minutes I believe. Check out the options of screen record.

To pull the file to your computer.... (the following command, or use Android Device Monitor

adb pull /sdcard/demo.mp4

I have used this to record demo's of apps, and even played youtube, and had it record that. It does not have audio, so that may be a major problem. But this is included in the sdk, and records any screen showing while it is recording.

like image 41
Hite Avatar answered Nov 09 '22 01:11

Hite