2

I am writing code to record video after analyzing frame. If the frame contains a redness level above 240 then it starts recording or redness goes bellow 230 stop video recording.

But the issue is that when media recorder starts recording than the onPreviewFrame method of Camera.PreviewCallback stopped working for customized android OS MIUI of my android device Redmi note 7 pro.

My code is bellow

private Camera.PreviewCallback previewCallback = new Camera.PreviewCallback() {

       /**
        * {@inheritDoc}
        */
       @Override
       public void onPreviewFrame(byte[] data, Camera cam) {
           if (data == null) throw new NullPointerException();
           Camera.Size size = cam.getParameters().getPreviewSize();
           if (size == null) throw new NullPointerException();


           int width = size.width;
           int height = size.height;

           // decodeYUV420SPtoRedAvg function to find redness lavel of frame 
           int imgAvg = ImageProcessing.decodeYUV420SPtoRedAvg(data.clone(), height, width);
           Log.i(TAG, "imgAvg=" + imgAvg);
           if (imgAvg == 0 || imgAvg == 255) {
               return;
           }

           if (isRecording) {
               long diffInMs = new Date(System.currentTimeMillis()).getTime() - startTime;
               Log.i(TAG, imgAvg + " imgAvg diffInMs1=" + diffInMs);

               mProgressBar.setProgress((int) diffInMs);
               if (diffInMs >= recordingMS + 1000) {
                   stopRecording();
                   i = 0;
                   mProgressBar.setVisibility(View.GONE);
                   tvStatingCount.setVisibility(View.GONE);
               }
               tvStatingCount.setText(getString(R.string.reading_started_please_hold_your_finger_steady_for_one_minute) + imgAvg);
           } else {
               mProgressBar.setVisibility(View.GONE);
               tvStatingCount.setVisibility(View.VISIBLE);
               tvStatingCount.setText(getString(R.string.please_place_your_finger_over_your_rear_camera_to_start_the_readingt) + imgAvg);
           }

           if (imgAvg > 240) {
               if (!isRecording) {
                   starRecording();
                   i = 0;
                   mProgressBar.setProgress(0);
                   mProgressBar.setVisibility(View.VISIBLE);
                   tvStatingCount.setText(getString(R.string.reading_started_please_hold_your_finger_steady_for_one_minute) + imgAvg);
               }
           } else {
               if (isRecording && imgAvg < 230) {
                   stopRecording();
               }
               /*mProgressBar.setVisibility(View.GONE);
               tvStatingCount.setText(getString(R.string.please_place_your_finger_over_your_rear_camera_to_start_the_readingt, imgAvg));*/
           }
       }
   };

The code is working for the native Android version. tested code in device moto, Samsung.

so anyone can help me to find out the solution?

0 Answers0