时差检查- Android 视频捕获
Time Difference Check- Android video capture
我正在做一个视频录像摄像头APP。如果相机在启动后立即停止,应用程序会崩溃,这可能是因为视频尺寸非常小。我只想在视频大小大于 1 秒时激活停止按钮。但问题是我无法正确找到当前时间和开始时间。找到两个时间因素的差异将有助于实施 2 秒检查。需要帮助。
private void onClickActions(View v)
{
float tt = start_time /10000000000000f;
float ct = ((System.currentTimeMillis() ) /10000000000000f);
Log.d("Before stoping S-Time ",tt+"");
Log.d("Before stoping C-Time ",ct+"");
if (recording && tt>=2.0f)
{
Log.d("After Stopping = ",tt+"");
// stop recording and release camera
mediaRecorder.stop(); // stop the recording
recording = false;
rec.setVisibility(View.INVISIBLE);
start_time = 0;
}
//remove time code to initial revert
if(v.getId()== start.getId() && ((CameraPreview.recordHappy || CameraPreview.recordSad))) {
prepareMediaRecorder();
recording = true;
mediaRecorder.start();
consent = true;
happyRecorded=true;
stop.setClickable(true);
start.setClickable(false);
if (AndroidVideoCaptureExample.iV.getVisibility()==View.VISIBLE)
AndroidVideoCaptureExample.iV.setVisibility(View.INVISIBLE);
//AndroidVideoCaptureExample.capture.setText("RECORDING STARTED!");
rec.setVisibility(View.VISIBLE);
start_time = (int)(System.currentTimeMillis());
//Toast.makeText(myContext, "You are being recorded now!", Toast.LENGTH_LONG);
}
if(v.getId()== stop.getId() && consent==true && recording==false) {
if((!CameraPreview.recordHappy && CameraPreview.recordSad))
{
releaseMediaRecorder(); // release the MediaRecorder object
Intent intent = new Intent();
intent.setClass(AndroidVideoCaptureExample.this, consentActivity.class);
startActivity(intent);
finish();
}
else {
CameraPreview.recordHappy = false;
CameraPreview.recordSad = true;
stop.setClickable(false);
start.setClickable(true);
recording = false;
AndroidVideoCaptureExample.capture.setText("Record Neutral Moment");
rec.setVisibility(View.INVISIBLE);
}
}
}
我认为您可能过度设计了一件简单的事情。你真的不需要计算记录时间,除非你在 UI 上显示它。如果您想禁用该按钮,只需在开始录制之前将其禁用,然后在 2 秒后使用 Handler
重新启用:
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
// enable stop button
}
},2000);
但是,我认为这不是很好的用户体验。如果你看像Google Camera这样的摄像头,你可以在启动后立即停止它,它不会记录任何东西。为此,需要在调用mediaRecorder.stop()
时捕获RuntimeException
,然后检查并清理生成的文件。如果它是空的然后删除它并且不要向 UI.
抛出错误
我正在做一个视频录像摄像头APP。如果相机在启动后立即停止,应用程序会崩溃,这可能是因为视频尺寸非常小。我只想在视频大小大于 1 秒时激活停止按钮。但问题是我无法正确找到当前时间和开始时间。找到两个时间因素的差异将有助于实施 2 秒检查。需要帮助。
private void onClickActions(View v)
{
float tt = start_time /10000000000000f;
float ct = ((System.currentTimeMillis() ) /10000000000000f);
Log.d("Before stoping S-Time ",tt+"");
Log.d("Before stoping C-Time ",ct+"");
if (recording && tt>=2.0f)
{
Log.d("After Stopping = ",tt+"");
// stop recording and release camera
mediaRecorder.stop(); // stop the recording
recording = false;
rec.setVisibility(View.INVISIBLE);
start_time = 0;
}
//remove time code to initial revert
if(v.getId()== start.getId() && ((CameraPreview.recordHappy || CameraPreview.recordSad))) {
prepareMediaRecorder();
recording = true;
mediaRecorder.start();
consent = true;
happyRecorded=true;
stop.setClickable(true);
start.setClickable(false);
if (AndroidVideoCaptureExample.iV.getVisibility()==View.VISIBLE)
AndroidVideoCaptureExample.iV.setVisibility(View.INVISIBLE);
//AndroidVideoCaptureExample.capture.setText("RECORDING STARTED!");
rec.setVisibility(View.VISIBLE);
start_time = (int)(System.currentTimeMillis());
//Toast.makeText(myContext, "You are being recorded now!", Toast.LENGTH_LONG);
}
if(v.getId()== stop.getId() && consent==true && recording==false) {
if((!CameraPreview.recordHappy && CameraPreview.recordSad))
{
releaseMediaRecorder(); // release the MediaRecorder object
Intent intent = new Intent();
intent.setClass(AndroidVideoCaptureExample.this, consentActivity.class);
startActivity(intent);
finish();
}
else {
CameraPreview.recordHappy = false;
CameraPreview.recordSad = true;
stop.setClickable(false);
start.setClickable(true);
recording = false;
AndroidVideoCaptureExample.capture.setText("Record Neutral Moment");
rec.setVisibility(View.INVISIBLE);
}
}
}
我认为您可能过度设计了一件简单的事情。你真的不需要计算记录时间,除非你在 UI 上显示它。如果您想禁用该按钮,只需在开始录制之前将其禁用,然后在 2 秒后使用 Handler
重新启用:
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
// enable stop button
}
},2000);
但是,我认为这不是很好的用户体验。如果你看像Google Camera这样的摄像头,你可以在启动后立即停止它,它不会记录任何东西。为此,需要在调用mediaRecorder.stop()
时捕获RuntimeException
,然后检查并清理生成的文件。如果它是空的然后删除它并且不要向 UI.