gpt4 book ai didi

java - 如何从 Java 在 Android 设备上运行 adb screenrecord 并结束屏幕录制?

转载 作者:搜寻专家 更新时间:2023-11-01 08:33:46 25 4
gpt4 key购买 nike

如何从 JavaAndroid 设备上运行 adb shell screenrecord 并结束 screenrecording

目前我必须指定--time-limit 来结束录制。如果我尝试在视频结束前捕捉视频,则会失败。

有没有办法告诉 adb 停止记录?有没有办法配置线程向 shell 命令发送 CTRL-C

这将在无根电话上运行。

代码

videoExecutor.submit(() -> {
//Start recording video
String recordVideo = "screenrecord --time-limit " + testRun.getVideoLength() + " " + "/sdcard/" + logDate + ".mp4";
try {
device.executeShell(recordVideo);
} catch (Exception e1) {
e1.printStackTrace();
}
sleep(testRun.getVideoLength()*ONE_SECOND + TWO_SECONDS); //gotta match the --time-limit above.

RemoteFile remote = new RemoteFile("/sdcard/" + logDate + ".mp4");
File local = new File(videoPath); //Save file to local machine
if(!local.getParentFile().exists()) {
local.getParentFile().mkdirs();
}

try {
//Copy video from phone to computer
try {
device.pull(remote, local);
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

});

最佳答案

发送 SIGINTSIGHUPscreenrecord进程会导致它停止记录。

我刚刚在 2 个单独的 adb shell session 中尝试了以下在无根(stock Android 6.0)手机上的操作:

在 session #1 中:

screenrecord /sdcard/Movies/test.mpg

在 session #2 中:

pkill -INT screenrecord

screenrecord 捕获在发出 pkill 命令后停止

关于java - 如何从 Java 在 Android 设备上运行 adb screenrecord 并结束屏幕录制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38363680/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com