diff --git a/src/main/java/eu/siacs/conversations/ui/RecordingActivity.java b/src/main/java/eu/siacs/conversations/ui/RecordingActivity.java index df3dabdceb0898d1f456c2b3220c55ebf8a1ab42..5823484b2207b5f24fdbbf578a2cf8bad90db7c6 100644 --- a/src/main/java/eu/siacs/conversations/ui/RecordingActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/RecordingActivity.java @@ -2,6 +2,7 @@ package eu.siacs.conversations.ui; import android.app.Activity; import android.content.Intent; +import android.content.SharedPreferences; import android.media.MediaRecorder; import android.net.Uri; import android.os.Build; @@ -10,6 +11,7 @@ import android.os.Environment; import android.os.FileObserver; import android.os.Handler; import android.os.SystemClock; +import android.preference.PreferenceManager; import android.util.Log; import android.view.View; import android.view.WindowManager; @@ -95,21 +97,32 @@ public class RecordingActivity extends Activity implements View.OnClickListener } } + protected SharedPreferences getPreferences() { + return PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); + } + private boolean startRecording() { mRecorder = new MediaRecorder(); mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); + final String userChosenCodec = getPreferences().getString("voice_message_codec", ""); final int outputFormat; - if (Config.USE_OPUS_VOICE_MESSAGES && Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + if (("opus".equals(userChosenCodec) || ("".equals(userChosenCodec) && Config.USE_OPUS_VOICE_MESSAGES)) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { outputFormat = MediaRecorder.OutputFormat.OGG; mRecorder.setOutputFormat(outputFormat); mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.OPUS); mRecorder.setAudioEncodingBitRate(32000); - } else { + } else if ("mpeg4".equals(userChosenCodec) || !Config.USE_OPUS_VOICE_MESSAGES) { outputFormat = MediaRecorder.OutputFormat.MPEG_4; mRecorder.setOutputFormat(outputFormat); mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); mRecorder.setAudioEncodingBitRate(96000); mRecorder.setAudioSamplingRate(22050); + } else { + outputFormat = MediaRecorder.OutputFormat.THREE_GPP; + mRecorder.setOutputFormat(outputFormat); + mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_WB); + mRecorder.setAudioEncodingBitRate(23850); + mRecorder.setAudioSamplingRate(16000); } setupOutputFile(outputFormat); mRecorder.setOutputFile(mOutputFile.getAbsolutePath()); @@ -191,6 +204,8 @@ public class RecordingActivity extends Activity implements View.OnClickListener extension = "m4a"; } else if (outputFormat == MediaRecorder.OutputFormat.OGG) { extension = "oga"; + } else if (outputFormat == MediaRecorder.OutputFormat.THREE_GPP) { + extension = "awb"; } else { throw new IllegalStateException("Unrecognized output format"); } diff --git a/src/main/res/values/arrays.xml b/src/main/res/values/arrays.xml index 1d6b5c94881dba3644e3abc6d1f1f56b083e8d08..6da1cbada13eacfa7379b0b55acd882d74a03a3d 100644 --- a/src/main/res/values/arrays.xml +++ b/src/main/res/values/arrays.xml @@ -128,4 +128,16 @@ JABBER_NETWORK LOCAL_SERVER + + + Opus (best) + MPEG4 + 3GPP + + + + opus + mpeg4 + 3gpp + diff --git a/src/main/res/xml/preferences.xml b/src/main/res/xml/preferences.xml index 85060370ecd5cd978039884e79812009a857dc26..41fa01d0f2e626c8e5462a05bfb700136da9ffcc 100644 --- a/src/main/res/xml/preferences.xml +++ b/src/main/res/xml/preferences.xml @@ -391,6 +391,12 @@ +