add sounds to shutter actions
This commit is contained in:
parent
e33d550ba6
commit
13d4f25810
|
@ -10,6 +10,7 @@ import android.graphics.SurfaceTexture
|
||||||
import android.hardware.camera2.*
|
import android.hardware.camera2.*
|
||||||
import android.hardware.camera2.params.MeteringRectangle
|
import android.hardware.camera2.params.MeteringRectangle
|
||||||
import android.media.ImageReader
|
import android.media.ImageReader
|
||||||
|
import android.media.MediaActionSound
|
||||||
import android.media.MediaRecorder
|
import android.media.MediaRecorder
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
@ -94,6 +95,7 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
||||||
private val mCameraToPreviewMatrix = Matrix()
|
private val mCameraToPreviewMatrix = Matrix()
|
||||||
private val mPreviewToCameraMatrix = Matrix()
|
private val mPreviewToCameraMatrix = Matrix()
|
||||||
private val mCameraOpenCloseLock = Semaphore(1)
|
private val mCameraOpenCloseLock = Semaphore(1)
|
||||||
|
private val mMediaActionSound = MediaActionSound()
|
||||||
private var mZoomRect = Rect()
|
private var mZoomRect = Rect()
|
||||||
|
|
||||||
constructor(context: Context) : super(context)
|
constructor(context: Context) : super(context)
|
||||||
|
@ -104,6 +106,7 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
||||||
mTextureView = textureView
|
mTextureView = textureView
|
||||||
mUseFrontCamera = !activity.config.alwaysOpenBackCamera && activity.config.lastUsedCamera == activity.getMyCamera().getBackCameraId().toString()
|
mUseFrontCamera = !activity.config.alwaysOpenBackCamera && activity.config.lastUsedCamera == activity.getMyCamera().getBackCameraId().toString()
|
||||||
mIsInVideoMode = !activity.config.initPhotoMode
|
mIsInVideoMode = !activity.config.initPhotoMode
|
||||||
|
loadSounds()
|
||||||
|
|
||||||
mTextureView.setOnTouchListener { view, event ->
|
mTextureView.setOnTouchListener { view, event ->
|
||||||
if (event.action == MotionEvent.ACTION_DOWN) {
|
if (event.action == MotionEvent.ACTION_DOWN) {
|
||||||
|
@ -176,6 +179,12 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun loadSounds() {
|
||||||
|
mMediaActionSound.load(MediaActionSound.START_VIDEO_RECORDING)
|
||||||
|
mMediaActionSound.load(MediaActionSound.STOP_VIDEO_RECORDING)
|
||||||
|
mMediaActionSound.load(MediaActionSound.SHUTTER_CLICK)
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
private fun openCamera(width: Int, height: Int) {
|
private fun openCamera(width: Int, height: Int) {
|
||||||
try {
|
try {
|
||||||
|
@ -513,6 +522,10 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mActivity.config.isSoundEnabled) {
|
||||||
|
mMediaActionSound.play(MediaActionSound.SHUTTER_CLICK)
|
||||||
|
}
|
||||||
|
|
||||||
mCameraState = STATE_PICTURE_TAKEN
|
mCameraState = STATE_PICTURE_TAKEN
|
||||||
mRotationAtCapture = mActivity.mLastHandledOrientation
|
mRotationAtCapture = mActivity.mLastHandledOrientation
|
||||||
val captureBuilder = mCameraDevice!!.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE).apply {
|
val captureBuilder = mCameraDevice!!.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE).apply {
|
||||||
|
@ -725,6 +738,9 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
||||||
private fun startRecording() {
|
private fun startRecording() {
|
||||||
closeCaptureSession()
|
closeCaptureSession()
|
||||||
setupMediaRecorder()
|
setupMediaRecorder()
|
||||||
|
if (mActivity.config.isSoundEnabled) {
|
||||||
|
mMediaActionSound.play(MediaActionSound.START_VIDEO_RECORDING)
|
||||||
|
}
|
||||||
val texture = mTextureView.surfaceTexture
|
val texture = mTextureView.surfaceTexture
|
||||||
texture.setDefaultBufferSize(mPreviewSize!!.width, mPreviewSize!!.height)
|
texture.setDefaultBufferSize(mPreviewSize!!.width, mPreviewSize!!.height)
|
||||||
mPreviewRequestBuilder = mCameraDevice!!.createCaptureRequest(CameraDevice.TEMPLATE_RECORD)
|
mPreviewRequestBuilder = mCameraDevice!!.createCaptureRequest(CameraDevice.TEMPLATE_RECORD)
|
||||||
|
@ -758,6 +774,10 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun stopRecording() {
|
private fun stopRecording() {
|
||||||
|
if (mActivity.config.isSoundEnabled) {
|
||||||
|
mMediaActionSound.play(MediaActionSound.STOP_VIDEO_RECORDING)
|
||||||
|
}
|
||||||
|
|
||||||
mIsRecording = false
|
mIsRecording = false
|
||||||
mMediaRecorder!!.stop()
|
mMediaRecorder!!.stop()
|
||||||
mMediaRecorder!!.reset()
|
mMediaRecorder!!.reset()
|
||||||
|
|
Loading…
Reference in New Issue