close #21, apply the Shutter sound option to video recording too

This commit is contained in:
tibbi 2016-09-20 20:57:16 +02:00
parent 18c060eb71
commit 075b0902b2
1 changed files with 12 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import android.content.Context;
import android.graphics.Point; import android.graphics.Point;
import android.graphics.Rect; import android.graphics.Rect;
import android.hardware.Camera; import android.hardware.Camera;
import android.media.AudioManager;
import android.media.CamcorderProfile; import android.media.CamcorderProfile;
import android.media.MediaActionSound; import android.media.MediaActionSound;
import android.media.MediaRecorder; import android.media.MediaRecorder;
@ -701,7 +702,9 @@ public class Preview extends ViewGroup
try { try {
mCamera.unlock(); mCamera.unlock();
toggleShutterSound(true);
mRecorder.start(); mRecorder.start();
toggleShutterSound(false);
mIsRecording = true; mIsRecording = true;
} catch (Exception e) { } catch (Exception e) {
Utils.showToast(mContext, R.string.video_setup_error); Utils.showToast(mContext, R.string.video_setup_error);
@ -713,10 +716,12 @@ public class Preview extends ViewGroup
private void stopRecording() { private void stopRecording() {
if (mRecorder != null && mIsRecording) { if (mRecorder != null && mIsRecording) {
try { try {
toggleShutterSound(true);
mRecorder.stop(); mRecorder.stop();
final String[] paths = {mCurVideoPath}; final String[] paths = {mCurVideoPath};
MediaScannerConnection.scanFile(mContext, paths, null, this); MediaScannerConnection.scanFile(mContext, paths, null, this);
} catch (RuntimeException e) { } catch (RuntimeException e) {
toggleShutterSound(false);
new File(mCurVideoPath).delete(); new File(mCurVideoPath).delete();
Utils.showToast(mContext, R.string.video_saving_error); Utils.showToast(mContext, R.string.video_saving_error);
Log.e(TAG, "stopRecording " + e.getMessage()); Log.e(TAG, "stopRecording " + e.getMessage());
@ -733,6 +738,12 @@ public class Preview extends ViewGroup
if (file.exists() && file.length() == 0) { if (file.exists() && file.length() == 0) {
file.delete(); file.delete();
} }
}
private void toggleShutterSound(Boolean mute) {
if (!Config.newInstance(mContext).getIsSoundEnabled()) {
((AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_SYSTEM, mute);
}
} }
@Override @Override
@ -747,6 +758,7 @@ public class Preview extends ViewGroup
@Override @Override
public void onScanCompleted(String path, Uri uri) { public void onScanCompleted(String path, Uri uri) {
mCallback.videoSaved(uri); mCallback.videoSaved(uri);
toggleShutterSound(false);
} }
private static class SizesComparator implements Comparator<Camera.Size>, Serializable { private static class SizesComparator implements Comparator<Camera.Size>, Serializable {