【发布时间】:2018-10-29 17:13:58
【问题描述】:
我正在尝试构建一个摩尔斯电码应用程序,它可以使用内置手电筒重播摩尔斯电码。所以我尝试了一些方法,其中一个稍微有效,但没有达到应有的效果。
所以基本上我输入了一条消息,让我们说“你好”。它转化为
.... . .-.. .-.. ---
然后我想通过点击一个按钮来重播它。 我尝试过不同的东西。这是我的第一次尝试:
public void onPlayflash(View view) throws InterruptedException, CameraAccessException {
if (result == null) {
output.setText("ERROR");
} else {
currentposition = 0;
if (currentposition < result.length()) {
String c = String.valueOf(result.charAt(0));
if (c.equals("-")) {
//timeinmillis = 1000;
//setTimer();
flash.setTorchMode(flash.getCameraIdList()[0], true);
Thread.sleep(2000);
flash.setTorchMode(flash.getCameraIdList()[0], false);
} else if (c.equals(".")) {
//timeinmillis = 500;
//setTimer();
flash.setTorchMode(flash.getCameraIdList()[0], true);
Thread.sleep(1000);
flash.setTorchMode(flash.getCameraIdList()[0], false);
} else {
Thread.sleep(2000);
}
currentposition += 1;
}
}
}
这不起作用。它只是说:
I/Choreographer: Skipped (*always a random number over 1000 here*) frames! The application may be doing too much work on its main thread.
然后我尝试了
public void onPlayflash(View view) throws InterruptedException, CameraAccessException {
if (result == null) {
output.setText("ERROR");
} else {
for (int i = 0; i < result.length(); i++) {
String c = String.valueOf(result.charAt(i));
if (c.equals("_")) {
flash.setTorchMode(flash.getCameraIdList()[0], true);
Thread.sleep(2000);
flash.setTorchMode(flash.getCameraIdList()[0], false);
Thread.sleep(500);
} else if (c.equals(".")) {
flash.setTorchMode(flash.getCameraIdList()[0], true);
Thread.sleep(1000);
flash.setTorchMode(flash.getCameraIdList()[0], false);
Thread.sleep(500);
} else {
Thread.sleep(1500);
}
}
}
}
这有点工作,但它仍然说
I/Choreographer: Skipped (*always a random number over 1000 here*) frames! The application may be doing too much work on its main thread.
实际上重播开始时很好,但随后它开始挣扎并跳过部分迭代。
如您所见,我也尝试了 android.os.CountDownTimer,但也没有成功。我只闪了一下,然后就停了。
如你所见,我还没有那么有经验'^^ 希望您能够帮助我。提前致谢!
【问题讨论】:
-
尝试让屏幕黑白闪烁。您可能会感到惊喜。
标签: java android android-camera2 flashlight morse-code