MediaActionSound support

pull/1/head
Mattia Iavarone 7 years ago
parent 89d1573717
commit db23050ee3
  1. 1
      README.md
  2. 14
      cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java
  3. 8
      cameraview/src/main/java/com/otaliastudios/cameraview/Camera2.java
  4. 4
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraController.java
  5. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraListener.java
  6. 45
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java
  7. 1
      cameraview/src/main/res/values/attrs.xml

@ -462,6 +462,7 @@ This is what was done since the library was forked. I have kept the original str
- *add multiple `CameraListener`s for events*
- *gesture framework support*
- *scroll gestures support*
- *MediaActionSound support*
These are still things that need to be done, off the top of my head:

@ -359,7 +359,6 @@ class Camera1 extends CameraController {
final int sensorToDisplay = computeSensorToDisplayOffset();
synchronized (mLock) {
Camera.Parameters params = mCamera.getParameters();
Log.e(TAG, "Setting exif rotation to "+exifRotation);
params.setRotation(exifRotation);
mCamera.setParameters(params);
}
@ -381,14 +380,14 @@ class Camera1 extends CameraController {
@Override
void captureSnapshot() {
if (!isCameraOpened()) return;
if (mIsCapturingImage) return;
boolean captureSnapshot() {
if (!isCameraOpened()) return false;
if (mIsCapturingImage) return false;
// This won't work while capturing a video.
// Switch to capturePicture.
if (mIsCapturingVideo) {
capturePicture();
return;
return false;
}
mIsCapturingImage = true;
mCamera.setOneShotPreviewCallback(new Camera.PreviewCallback() {
@ -420,6 +419,7 @@ class Camera1 extends CameraController {
}).start();
}
});
return true;
}
@Override
@ -554,7 +554,7 @@ class Camera1 extends CameraController {
}
@Override
void endVideo() {
boolean endVideo() {
if (mIsCapturingVideo) {
mIsCapturingVideo = false;
mMediaRecorder.stop();
@ -564,7 +564,9 @@ class Camera1 extends CameraController {
mCameraCallbacks.dispatchOnVideoTaken(mVideoFile);
mVideoFile = null;
}
return true;
}
return false;
}

@ -167,8 +167,8 @@ class Camera2 extends CameraController {
}
@Override
void captureSnapshot() {
boolean captureSnapshot() {
return true;
}
@Override
@ -177,8 +177,8 @@ class Camera2 extends CameraController {
}
@Override
void endVideo() {
boolean endVideo() {
return false;
}
@Override

@ -39,9 +39,9 @@ abstract class CameraController implements Preview.SurfaceCallback {
abstract void setLocation(double latitude, double longitude);
abstract boolean capturePicture();
abstract void captureSnapshot();
abstract boolean captureSnapshot();
abstract boolean startVideo(@NonNull File file);
abstract void endVideo();
abstract boolean endVideo();
abstract Size getCaptureSize();
abstract Size getPreviewSize();

@ -62,7 +62,7 @@ public abstract class CameraListener {
/**
* Notifies that the device was tilted or the window offset changed.
* The orientation passed is exactly the rotation that a View should have,
* The orientation passed is exactly the counter-clockwise rotation that a View should have,
* in order to appear correctly oriented to the user, considering the way she is
* holding the device, and the native activity orientation.
*

@ -1,6 +1,7 @@
package com.otaliastudios.cameraview;
import android.Manifest;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
@ -11,6 +12,7 @@ import android.content.res.TypedArray;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.YuvImage;
import android.media.MediaActionSound;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
@ -95,9 +97,11 @@ public class CameraView extends FrameLayout {
@SuppressWarnings("WrongConstant")
private void init(@NonNull Context context, @Nullable AttributeSet attrs) {
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CameraView, 0, 0);
mJpegQuality = a.getInteger(R.styleable.CameraView_cameraJpegQuality, DEFAULT_JPEG_QUALITY);
mCropOutput = a.getBoolean(R.styleable.CameraView_cameraCropOutput, DEFAULT_CROP_OUTPUT);
// Self managed
int jpegQuality = a.getInteger(R.styleable.CameraView_cameraJpegQuality, DEFAULT_JPEG_QUALITY);
boolean cropOutput = a.getBoolean(R.styleable.CameraView_cameraCropOutput, DEFAULT_CROP_OUTPUT);
// Camera controller params
Facing facing = Facing.fromValue(a.getInteger(R.styleable.CameraView_cameraFacing, Facing.DEFAULT.value()));
Flash flash = Flash.fromValue(a.getInteger(R.styleable.CameraView_cameraFlash, Flash.DEFAULT.value()));
Grid grid = Grid.fromValue(a.getInteger(R.styleable.CameraView_cameraGrid, Grid.DEFAULT.value()));
@ -105,6 +109,7 @@ public class CameraView extends FrameLayout {
VideoQuality videoQuality = VideoQuality.fromValue(a.getInteger(R.styleable.CameraView_cameraVideoQuality, VideoQuality.DEFAULT.value()));
SessionType sessionType = SessionType.fromValue(a.getInteger(R.styleable.CameraView_cameraSessionType, SessionType.DEFAULT.value()));
// Gestures
GestureAction tapGesture = GestureAction.fromValue(a.getInteger(R.styleable.CameraView_cameraGestureTap, GestureAction.DEFAULT_TAP.value()));
GestureAction longTapGesture = GestureAction.fromValue(a.getInteger(R.styleable.CameraView_cameraGestureLongTap, GestureAction.DEFAULT_LONG_TAP.value()));
GestureAction pinchGesture = GestureAction.fromValue(a.getInteger(R.styleable.CameraView_cameraGesturePinch, GestureAction.DEFAULT_PINCH.value()));
@ -125,12 +130,20 @@ public class CameraView extends FrameLayout {
addView(mScrollGestureLayout);
mIsStarted = false;
// Self managed
setCropOutput(cropOutput);
setJpegQuality(jpegQuality);
// Camera controller params
setFacing(facing);
setFlash(flash);
setSessionType(sessionType);
setVideoQuality(videoQuality);
setWhiteBalance(whiteBalance);
setGrid(grid);
// Gestures
mapGesture(Gesture.TAP, tapGesture);
// mapGesture(Gesture.DOUBLE_TAP, doubleTapGesture);
mapGesture(Gesture.LONG_TAP, longTapGesture);
@ -997,7 +1010,9 @@ public class CameraView extends FrameLayout {
* @see #captureSnapshot()
*/
public void capturePicture() {
mCameraController.capturePicture();
if (mCameraController.capturePicture() && mUseSounds) {
// TODO: sound
}
}
@ -1012,7 +1027,10 @@ public class CameraView extends FrameLayout {
* @see #capturePicture()
*/
public void captureSnapshot() {
mCameraController.captureSnapshot();
if (mCameraController.captureSnapshot() && mUseSounds) {
//noinspection all
sound(MediaActionSound.SHUTTER_CLICK);
}
}
@ -1079,9 +1097,10 @@ public class CameraView extends FrameLayout {
* This will fire {@link CameraListener#onVideoTaken(File)}.
*/
public void stopCapturingVideo() {
mCameraController.endVideo();
if (mCameraController.endVideo()) {
if (getKeepScreenOn() != mKeepScreenOn) setKeepScreenOn(mKeepScreenOn);
}
}
/**
@ -1144,6 +1163,17 @@ public class CameraView extends FrameLayout {
// ----------------------
private MediaActionSound mSound;
private final boolean mUseSounds = Build.VERSION.SDK_INT >= 16;
@SuppressWarnings("all")
private void sound(int soundType) {
if (mUseSounds) {
if (mSound == null) mSound = new MediaActionSound();
mSound.play(soundType);
}
}
class CameraCallbacks {
private ArrayList<CameraListener> mListeners;
@ -1289,6 +1319,11 @@ public class CameraView extends FrameLayout {
uiHandler.post(new Runnable() {
@Override
public void run() {
if (success && mUseSounds) {
//noinspection all
sound(MediaActionSound.FOCUS_COMPLETE);
}
if (gesture != null && mGestureMap.get(gesture) == GestureAction.FOCUS_WITH_MARKER) {
mTapGestureLayout.onFocusEnd(success);
}

@ -40,7 +40,6 @@
<enum name="exposureCorrection" value="5" />
</attr>
<attr name="cameraFacing" format="enum">
<enum name="back" value="0" />
<enum name="front" value="1" />

Loading…
Cancel
Save