Skip to content

Commit

Permalink
Merge pull request #2 from ricohapi/feature/Fix_ShutterCallback
Browse files Browse the repository at this point in the history
Fix ShutterCallback
  • Loading branch information
shohara authored Aug 30, 2018
2 parents 3b31c00 + 04c9cc2 commit d7a5f09
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
15 changes: 12 additions & 3 deletions plugin/src/main/java/com/theta360/pluginsample/CameraFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class CameraFragment extends Fragment {
private MediaRecorder mMediaRecorder;//for video
private boolean isSurface = false;
private boolean isCapturing = false;
private boolean isShutter = false;
private File instanceRecordMP4;
private File instanceRecordWAV;
private MediaRecorder.OnInfoListener onInfoListener = new MediaRecorder.OnInfoListener() {
Expand Down Expand Up @@ -93,7 +94,11 @@ public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
private Camera.ShutterCallback onShutterCallback = new Camera.ShutterCallback() {
@Override
public void onShutter() {
mCallback.onShutter();
// ShutterCallback is called twice.
if (!isShutter) {
mCallback.onShutter();
isShutter = true;
}
}
};
private Camera.PictureCallback onJpegPictureCallback = new Camera.PictureCallback() {
Expand All @@ -110,6 +115,8 @@ public void onPictureTaken(byte[] data, Camera camera) {
e.printStackTrace();
}

mCallback.onPictureTaken();

mCamera.startPreview();
isCapturing = false;
}
Expand Down Expand Up @@ -208,6 +215,7 @@ public void stopWatching() {
public void takePicture() {
if (!isCapturing) {
isCapturing = true;
isShutter = false;

mParameters.setPictureSize(5376, 2688);
mParameters.set("RIC_SHOOTING_MODE", "RicStillCaptureStd");
Expand All @@ -222,13 +230,15 @@ public void takePicture() {
}
}

public boolean isMediaRecorder() {
public boolean isMediaRecorderNull() {
return mMediaRecorder == null;
}

public boolean takeVideo() {
boolean result = true;
if (mMediaRecorder == null) {
mMediaRecorder = new MediaRecorder();

mAudioManager.setParameters("RicUseBFormat=true");
mAudioManager.setParameters("RicMicSelect=RicMicSelectAuto");
mAudioManager
Expand All @@ -245,7 +255,6 @@ public boolean takeVideo() {

mCamera.setParameters(mParameters);

mMediaRecorder = new MediaRecorder();
mCamera.unlock();

mMediaRecorder.setCamera(mCamera);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public void onKeyUp(int keyCode, KeyEvent event) {
if (keyCode == KeyReceiver.KEYCODE_MEDIA_RECORD) {
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment);
if (fragment != null && fragment instanceof CameraFragment) {
if (((CameraFragment) fragment).isMediaRecorder()) {
// not recording video
if (((CameraFragment) fragment).isMediaRecorderNull() && !(((CameraFragment) fragment).isCapturing())) {
// not recording video or capturing still
isVideo = !isVideo;
updateLED();
}
Expand Down Expand Up @@ -123,7 +123,7 @@ private boolean takeVideo() {
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment);
if (fragment != null && fragment instanceof CameraFragment) {

if (((CameraFragment) fragment).isMediaRecorder()) {
if (((CameraFragment) fragment).isMediaRecorderNull()) {
// start recording
if (!(((CameraFragment) fragment).isCapturing())) {
notificationAudioMovStart();
Expand Down Expand Up @@ -156,7 +156,7 @@ private void endProcess() {
if (!isEnded) {
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment);
if (fragment != null && fragment instanceof CameraFragment) {
if (!((CameraFragment) fragment).isMediaRecorder()) {
if (!((CameraFragment) fragment).isMediaRecorderNull()) {
takeVideo(); // stop recording
}
}
Expand Down

0 comments on commit d7a5f09

Please sign in to comment.