From 1c5ca5bdb46a7236f640e3225bf95722f34b4cad Mon Sep 17 00:00:00 2001 From: Leroy Witteveen Date: Wed, 20 Mar 2019 22:10:37 +0100 Subject: [PATCH] Implemented being able to toggle audio recording. Closes #14. --- build.gradle | 2 ++ .../com/opendashcam/BackgroundVideoRecorder.java | 16 +++++++++++++--- mobile/src/main/res/values/strings.xml | 3 +++ mobile/src/main/res/xml/pref_general.xml | 6 ++++++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index a47fa4b..5120095 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,7 @@ buildscript { repositories { + google() jcenter() } dependencies { @@ -14,6 +15,7 @@ buildscript { allprojects { repositories { + google() jcenter() } } diff --git a/mobile/src/main/java/com/opendashcam/BackgroundVideoRecorder.java b/mobile/src/main/java/com/opendashcam/BackgroundVideoRecorder.java index c6287e5..82ba25f 100644 --- a/mobile/src/main/java/com/opendashcam/BackgroundVideoRecorder.java +++ b/mobile/src/main/java/com/opendashcam/BackgroundVideoRecorder.java @@ -157,9 +157,19 @@ private void initMediaRecorder(final SurfaceHolder surfaceHolder) { mediaRecorder = new MediaRecorder(); mediaRecorder.setCamera(camera); // TODO See if we can remove this line. We can't, because media recorder should know what camera object will be used - mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER); + mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); - mediaRecorder.setProfile(camcorderProfile); + + if (settings.getBoolean("record_audio", true)) { + mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER); + mediaRecorder.setProfile(camcorderProfile); + } else { + mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); + mediaRecorder.setVideoFrameRate(camcorderProfile.videoFrameRate); + mediaRecorder.setVideoSize(camcorderProfile.videoFrameWidth, camcorderProfile.videoFrameHeight); + mediaRecorder.setVideoEncoder(camcorderProfile.videoCodec); + } + mediaRecorder.setVideoEncodingBitRate(3000000); mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface()); // Store previous and current recording filenames, so that they may be retrieved by the @@ -356,4 +366,4 @@ public void surfaceDestroyed(SurfaceHolder surfaceHolder) { public IBinder onBind(Intent intent) { return null; } -} \ No newline at end of file +} diff --git a/mobile/src/main/res/values/strings.xml b/mobile/src/main/res/values/strings.xml index 52c7d5c..abc25d2 100644 --- a/mobile/src/main/res/values/strings.xml +++ b/mobile/src/main/res/values/strings.xml @@ -48,6 +48,9 @@ Starred recordings will not be deleted. you start the app + Record audio + Includes audio in the video recordings + Delete all recordings Delete all recordings created by Open Dash Cam diff --git a/mobile/src/main/res/xml/pref_general.xml b/mobile/src/main/res/xml/pref_general.xml index 69012b8..ad1ef8c 100644 --- a/mobile/src/main/res/xml/pref_general.xml +++ b/mobile/src/main/res/xml/pref_general.xml @@ -18,6 +18,12 @@ android:key="start_maps_in_background" android:summary="@string/pref_description_start_maps_in_background" android:title="@string/pref_title_start_maps_in_background" /> + +