From 90089f9eddde732725c43dcad07f4567ed8cb776 Mon Sep 17 00:00:00 2001 From: Wu-cheng Li Date: Fri, 18 Nov 2011 18:28:09 +0800 Subject: Update camera sound API. bug:5640219 Change-Id: Ic3af6527f3025ec04ba4be16b621b462f89953f1 --- src/com/android/camera/Camera.java | 7 ++++++- src/com/android/camera/EffectsRecorder.java | 8 ++++++-- src/com/android/camera/FocusManager.java | 4 ++-- src/com/android/camera/panorama/PanoramaActivity.java | 10 +++++++--- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java index 6bded2c..5a1beb6 100644 --- a/src/com/android/camera/Camera.java +++ b/src/com/android/camera/Camera.java @@ -42,6 +42,7 @@ import android.hardware.Camera.FaceDetectionListener; import android.hardware.Camera.Parameters; import android.hardware.Camera.PictureCallback; import android.hardware.Camera.Size; +import android.hardware.CameraSound; import android.location.Location; import android.media.CameraProfile; import android.net.Uri; @@ -182,6 +183,8 @@ public class Camera extends ActivityBase implements FocusManager.Listener, // generating thumbnails. This reduces the shot-to-shot time. private ImageSaver mImageSaver; + private CameraSound mCameraSound; + private Runnable mDoSnapRunnable = new Runnable() { public void run() { onShutterButtonClick(); @@ -1062,7 +1065,7 @@ public class Camera extends ActivityBase implements FocusManager.Listener, @Override public void playSound(int soundId) { - mCameraDevice.playSound(soundId); + mCameraSound.playSound(soundId); } private boolean saveDataToFile(String filePath, byte[] data) { @@ -1200,6 +1203,7 @@ public class Camera extends ActivityBase implements FocusManager.Listener, // Do this after starting preview because it depends on camera // parameters. initializeIndicatorControl(); + mCameraSound = new CameraSound(); // Make sure preview is started. try { @@ -1571,6 +1575,7 @@ public class Camera extends ActivityBase implements FocusManager.Listener, stopPreview(); // Close the camera now because other activities may need to use it. closeCamera(); + mCameraSound.release(); resetScreenOn(); // Clear UI. diff --git a/src/com/android/camera/EffectsRecorder.java b/src/com/android/camera/EffectsRecorder.java index 3d2aebf..b649bc2 100644 --- a/src/com/android/camera/EffectsRecorder.java +++ b/src/com/android/camera/EffectsRecorder.java @@ -32,6 +32,7 @@ import android.filterpacks.videosrc.SurfaceTextureSource.SurfaceTextureSourceLis import android.graphics.SurfaceTexture; import android.hardware.Camera; +import android.hardware.CameraSound; import android.media.MediaRecorder; import android.media.CamcorderProfile; import android.os.Handler; @@ -117,6 +118,7 @@ public class EffectsRecorder { private boolean mLogVerbose = Log.isLoggable(TAG, Log.VERBOSE); private static final String TAG = "effectsrecorder"; + private CameraSound mCameraSound; /** Determine if a given effect is supported at runtime * Some effects require libraries not available on all devices @@ -136,6 +138,7 @@ public class EffectsRecorder { if (mLogVerbose) Log.v(TAG, "EffectsRecorder created (" + this + ")"); mContext = context; mHandler = new Handler(Looper.getMainLooper()); + mCameraSound = new CameraSound(); } public void setCamera(Camera cameraDevice) { @@ -690,7 +693,7 @@ public class EffectsRecorder { recorder.setInputValue("maxFileSize", mMaxFileSize); recorder.setInputValue("maxDurationMs", mMaxDurationMs); recorder.setInputValue("recording", true); - mCameraDevice.playSound(Camera.Sound.START_VIDEO_RECORDING); + mCameraSound.playSound(CameraSound.START_VIDEO_RECORDING); mState = STATE_RECORD; } @@ -710,7 +713,7 @@ public class EffectsRecorder { } Filter recorder = mRunner.getGraph().getFilter("recorder"); recorder.setInputValue("recording", false); - mCameraDevice.playSound(Camera.Sound.STOP_VIDEO_RECORDING); + mCameraSound.playSound(CameraSound.STOP_VIDEO_RECORDING); mState = STATE_PREVIEW; } @@ -740,6 +743,7 @@ public class EffectsRecorder { } catch(IOException e) { throw new RuntimeException("Unable to connect camera to effect input", e); } + mCameraSound.release(); mState = STATE_CONFIGURE; mOldRunner = mRunner; diff --git a/src/com/android/camera/FocusManager.java b/src/com/android/camera/FocusManager.java index 8c3f14d..72a0919 100644 --- a/src/com/android/camera/FocusManager.java +++ b/src/com/android/camera/FocusManager.java @@ -26,7 +26,7 @@ import android.graphics.Rect; import android.graphics.RectF; import android.hardware.Camera.Area; import android.hardware.Camera.Parameters; -import android.hardware.Camera.Sound; +import android.hardware.CameraSound; import android.os.Handler; import android.os.Message; import android.util.Log; @@ -224,7 +224,7 @@ public class FocusManager { // so the state is always STATE_FOCUSING. if (!Parameters.FOCUS_MODE_CONTINUOUS_PICTURE. equals(mFocusMode)) { - mListener.playSound(Sound.FOCUS_COMPLETE); + mListener.playSound(CameraSound.FOCUS_COMPLETE); } } else { mState = STATE_FAIL; diff --git a/src/com/android/camera/panorama/PanoramaActivity.java b/src/com/android/camera/panorama/PanoramaActivity.java index 69fcc83..d446e41 100755 --- a/src/com/android/camera/panorama/PanoramaActivity.java +++ b/src/com/android/camera/panorama/PanoramaActivity.java @@ -49,7 +49,7 @@ import android.graphics.SurfaceTexture; import android.graphics.YuvImage; import android.hardware.Camera.Parameters; import android.hardware.Camera.Size; -import android.hardware.Camera.Sound; +import android.hardware.CameraSound; import android.hardware.Sensor; import android.hardware.SensorManager; import android.media.ExifInterface; @@ -176,6 +176,8 @@ public class PanoramaActivity extends ActivityBase implements private RotateDialogController mRotateDialog; + private CameraSound mCameraSound; + private class MosaicJpeg { public MosaicJpeg(byte[] data, int width, int height) { this.data = data; @@ -271,6 +273,7 @@ public class PanoramaActivity extends ActivityBase implements mDialogOkString = getResources().getString(R.string.dialog_ok); mDialogPanoramaFailedString = getResources().getString(R.string.pano_dialog_panorama_failed); + mCameraSound = new CameraSound(); mMainHandler = new Handler() { @Override @@ -733,11 +736,11 @@ public class PanoramaActivity extends ActivityBase implements // right now. switch (mCaptureState) { case CAPTURE_STATE_VIEWFINDER: - mCameraDevice.playSound(Sound.START_VIDEO_RECORDING); + mCameraSound.playSound(CameraSound.START_VIDEO_RECORDING); startCapture(); break; case CAPTURE_STATE_MOSAIC: - mCameraDevice.playSound(Sound.STOP_VIDEO_RECORDING); + mCameraSound.playSound(CameraSound.STOP_VIDEO_RECORDING); stopCapture(false); } } @@ -977,6 +980,7 @@ public class PanoramaActivity extends ActivityBase implements clearMosaicFrameProcessorIfNeeded(); mOrientationEventListener.disable(); resetScreenOn(); + mCameraSound.release(); System.gc(); } -- cgit v1.1