我正在编写代码以在分析帧后录制视频。如果帧包含高于 240 的红度级别,则它开始录制或红度低于 230 停止视频录制。
但问题是,当媒体记录器开始录制时,Camera.PreviewCallback 的onPreviewFrame方法停止为我的 android 设备Redmi note 7 pro的自定义 android OS MIUI 工作。
我的代码如下
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));*/
}
}
};
该代码适用于本机 Android 版本。在设备 moto,Samsung 中测试代码。
所以任何人都可以帮助我找出解决方案?