0

我正在开发一个视频录制相机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);

        }
    }
}
4

1 回答 1

1

我认为您可能过度设计了一件简单的事情。除非您在 UI 上显示它,否则您实际上不需要计算记录时间。如果要禁用该按钮,只需在开始录制之前将其禁用,然后使用Handler2 秒后重新启用:

        new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
            @Override
            public void run() {
                // enable stop button
            }
        },2000);

但是,我认为这不是一个很好的用户体验。如果你看像谷歌相机这样的相机,你可以在启动后立即停止它,它不会记录任何东西。为此,您需要RuntimeException在调用时捕获mediaRecorder.stop(),然后检查并清理生成的文件。如果它为空,则将其删除,并且不要向 UI 抛出错误。

于 2015-12-16T18:09:47.233 回答