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)?
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?
Please provide a sample code solution for this.
Important: These steps work on phones running Android 12 and up, on most screens that allow you to scroll. Open the screen that you want to capture. Press the Power and Volume down buttons at the same time. At the bottom, tap Capture more.
Android Screen Recorder Pull down the notification shade from the top of the screen to view your quick settings options. Tap the Screen Recorder icon and give permission to the device to record the screen (you might have to edit the default icons that appear). Determine what sound, if any, you want recorded.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With