我开发了一款Android应用程序,可以在录制视频时拍照,录制视频和拍照。要在recorder.setCamera()
我必须解锁相机camera.unlock()
之前录制视频。
之后录制开始,一切都很好。之后我有一个可见的按钮,如果我在其上标签,相机正在拍照camera.takePicture(null, null, jpegCallback);
。
之后,异步响应将出现在onPictureTaken()
的覆盖PictureCallback jpegCallback
方法中,并且一切似乎都是合法的,但仅限于某些设备。
是否有人知道为什么我在使用unlock()相机录制视频时无法拍照。
有关详细信息,请在此处查看我的详细问题:
Can't take photo while recording a video only if camera is unlock() for record
答案 0 :(得分:-1)
public void onClick(View v) {
// TODO Auto-generated method stub
// if(v == myButton)
// {
if (recording) {
// stop recording and release camera
// type.setVisibility(View.GONE);1
type.setText("");
myChronometer.stop();
myChronometer.setBase(SystemClock.elapsedRealtime());
// mediaRecorder.stop(); // stop the recording
releaseMediaRecorder(); // release the MediaRecorder object
//
myCamera.lock();
recording = false;
// "/sdcard/fivo_flim/" + "fivo_flim_"+video_no
// + ".mp4";
System.out.println("11111111111 "+SessionManager.getVideoCount(prefs1));
new UploadPicture(VideoScreen.this, mApi, "/", new File(
"/sdcard/record/" + "record"
+ SessionManager.getVideoCount(prefs1) + ".mp4"))
.execute();
SessionManager.saveVideoCount(prefs1,
SessionManager.getVideoCount(prefs1) + 1);
mWakeLock.release();
System.out.println("uuuuuuuuuuuuuuuuuu");
} else {
// Release Camera before MediaRecorder start
releaseCamera();
mWakeLock.acquire();
if (!prepareMediaRecorder()) {
Toast.makeText(
VideoScreen.this,
"Fail in PrepareCamera()!\n \n Please Insert SD Card or\n Restart your phone ",
Toast.LENGTH_LONG).show();
finish();
}
System.out.println("prepare media recorder");
try {
mediaRecorder.prepare();
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("Starting Media Recorder");
try {
mediaRecorder.start();
} catch (Exception e) {
// TODO: handle exception
System.out.println("exception is " + e);
}
type.setText("Recording...");
myChronometer.setBase(SystemClock.elapsedRealtime());
myChronometer.start();
recording = true;
myButton.setClickable(false);
try {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
myButton.setClickable(true);
}
}, 3000);
} catch (Exception e) {
e.printStackTrace();
}
}
}
@SuppressLint({ "NewApi", "SdCardPath" })
private boolean prepareMediaRecorder() {
myCamera = getCameraInstance();
mediaRecorder = new MediaRecorder();
myCamera.setDisplayOrientation(90);
myCamera.unlock();
mediaRecorder.setCamera(myCamera);
mediaRecorder.setOrientationHint(90);
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRecorder.setProfile(CamcorderProfile
.get(CamcorderProfile.QUALITY_HIGH));
File mediaStorageDir = new File("/sdcard/record/");
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
Logger.Debug("failed to create directory");
}
}
video_no=SessionManager.getVideoCount(prefs1);
mFiles.add("/sdcard/record/" + "record" + video_no
+ ".mp4");
mediaRecorder.setOutputFile("/sdcard/record/" + "record"
+ video_no + ".mp4");
video_no++;
mediaRecorder.setPreviewDisplay(myCameraSurfaceView.getHolder()
.getSurface());
try {
mediaRecorder.prepare();
} catch (IllegalStateException e) {
releaseMediaRecorder();
return false;
} catch (IOException e) {
releaseMediaRecorder();
return false;
}
return true;
}
@SuppressLint("SdCardPath")
private void releaseMediaRecorder() {
if (mediaRecorder != null) {
mediaRecorder.reset();
mediaRecorder.release();
mediaRecorder = null;
myCamera.lock();
}
}
private void releaseCamera() {
if (myCamera != null) {
myCamera.release();
myCamera = null;
}
}
}