Skip to content

Commit

Permalink
Bring MediaRecorder settings in one place
Browse files Browse the repository at this point in the history
Signed-off-by: Daniele Ricci <[email protected]>
  • Loading branch information
daniele-athome committed Mar 29, 2020
1 parent 89c70c5 commit b834de1
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 9 deletions.
7 changes: 2 additions & 5 deletions app/src/main/java/org/kontalk/ui/AudioDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.kontalk.Log;
import org.kontalk.R;
import org.kontalk.ui.view.CircularSeekBar;
import org.kontalk.util.AudioRecording;
import org.kontalk.util.MediaStorage;
import org.kontalk.util.Permissions;

Expand Down Expand Up @@ -369,11 +370,7 @@ void startRecord() throws IOException {
setupViewForRecording(0);

try {
MediaRecorder recorder = mData.getRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setOutputFile(mFile.getAbsolutePath());
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
AudioRecording.setupMediaRecorder(mData.getRecorder(), mFile);
// start recording
mData.startRecording();
mStatus = STATUS_RECORDING;
Expand Down
6 changes: 2 additions & 4 deletions app/src/main/java/org/kontalk/ui/view/ComposerBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import org.kontalk.message.AudioComponent;
import org.kontalk.ui.AudioDialog;
import org.kontalk.ui.ComposeMessage;
import org.kontalk.util.AudioRecording;
import org.kontalk.util.MediaStorage;
import org.kontalk.util.MessageUtils;
import org.kontalk.util.Permissions;
Expand Down Expand Up @@ -562,10 +563,7 @@ private void doStartRecording() {

mRecord = new MediaRecorder();
try {
mRecord.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecord.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecord.setOutputFile(mRecordFile.getAbsolutePath());
mRecord.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
AudioRecording.setupMediaRecorder(mRecord, mRecordFile);
mVibrator.vibrate(AUDIO_RECORD_VIBRATION);
startTimer();
mRecord.prepare();
Expand Down
44 changes: 44 additions & 0 deletions app/src/main/java/org/kontalk/util/AudioRecording.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Kontalk Android client
* Copyright (C) 2020 Kontalk Devteam <[email protected]>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.kontalk.util

import android.media.MediaRecorder
import java.io.File


/**
* Audio recording utilities.
* @author Daniele Ricci
*/
class AudioRecording {

companion object {

@JvmStatic
fun setupMediaRecorder(recorder: MediaRecorder, outputFile: File): MediaRecorder {
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setOutputFile(outputFile.absolutePath);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
return recorder;
}

}

}

0 comments on commit b834de1

Please sign in to comment.