Allow to choose a audio source

Choose audio from:
 MediaRecorder.AudioSource.CAMCORDER,
 MediaRecorder.AudioSource.DEFAULT,
 MediaRecorder.AudioSource.UNPROCESSED,
 MediaRecorder.AudioSource.MIC,
 MediaRecorder.AudioSource.VOICE_COMMUNICATION,
 MediaRecorder.AudioSource.VOICE_PERFORMANCE)
This commit is contained in:
evermind 2022-10-14 15:20:40 +02:00
parent 54477079b7
commit e6315ca93a
7 changed files with 70 additions and 3 deletions

View File

@ -11,6 +11,7 @@ import com.simplemobiletools.commons.helpers.isTiramisuPlus
import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.voicerecorder.R
import com.simplemobiletools.voicerecorder.extensions.config
import com.simplemobiletools.voicerecorder.helpers.AUDIO_SOURCE
import com.simplemobiletools.voicerecorder.helpers.BITRATES
import com.simplemobiletools.voicerecorder.helpers.EXTENSION_M4A
import com.simplemobiletools.voicerecorder.helpers.EXTENSION_MP3
@ -39,6 +40,7 @@ class SettingsActivity : SimpleActivity() {
setupSaveRecordingsFolder()
setupExtension()
setupBitrate()
setupAudioSource()
setupRecordAfterLaunch()
updateTextColors(settings_nested_scrollview)
@ -172,4 +174,16 @@ class SettingsActivity : SimpleActivity() {
config.recordAfterLaunch = settings_record_after_launch.isChecked
}
}
private fun setupAudioSource() {
settings_audio_source.text = config.getAudioSourceText(config.audio_source)
settings_audio_source_holder.setOnClickListener {
val items = AUDIO_SOURCE.map { RadioItem(it, config.getAudioSourceText(it)) } as ArrayList
RadioGroupDialog(this@SettingsActivity, items, config.audio_source) {
config.audio_source = it as Int
settings_audio_source.text = config.getAudioSourceText(config.audio_source)
}
}
}
}

View File

@ -23,6 +23,20 @@ class Config(context: Context) : BaseConfig(context) {
get() = prefs.getInt(EXTENSION, EXTENSION_M4A)
set(extension) = prefs.edit().putInt(EXTENSION, extension).apply()
var audio_source: Int
get() = prefs.getInt(AUDIO_SRC, DEFAULT_AUDIO_SOURCE)
set(audio_source) = prefs.edit().putInt(AUDIO_SRC, audio_source).apply()
fun getAudioSourceText(audio_source: Int) = context.getString(when (audio_source) {
MediaRecorder.AudioSource.CAMCORDER -> R.string.audio_source_camcorder
MediaRecorder.AudioSource.DEFAULT -> R.string.audio_source_default
MediaRecorder.AudioSource.UNPROCESSED -> R.string.audio_source_unprocessed
MediaRecorder.AudioSource.MIC -> R.string.audio_source_microphone
MediaRecorder.AudioSource.VOICE_COMMUNICATION -> R.string.audio_source_voice_communication
MediaRecorder.AudioSource.VOICE_PERFORMANCE -> R.string.audio_source_voice_performance
else -> R.string.audio_source_camcorder
})
var bitrate: Int
get() = prefs.getInt(BITRATE, DEFAULT_BITRATE)
set(bitrate) = prefs.edit().putInt(BITRATE, bitrate).apply()

View File

@ -2,6 +2,7 @@ package com.simplemobiletools.voicerecorder.helpers
import android.annotation.SuppressLint
import android.content.ContentUris
import android.media.MediaRecorder
import android.net.Uri
import android.provider.MediaStore
import android.provider.MediaStore.Audio.Media
@ -18,6 +19,15 @@ const val EXTENSION_M4A = 0
const val EXTENSION_MP3 = 1
const val EXTENSION_OGG = 2
val AUDIO_SOURCE = arrayListOf(
MediaRecorder.AudioSource.CAMCORDER,
MediaRecorder.AudioSource.DEFAULT,
MediaRecorder.AudioSource.UNPROCESSED,
MediaRecorder.AudioSource.MIC,
MediaRecorder.AudioSource.VOICE_COMMUNICATION,
MediaRecorder.AudioSource.VOICE_PERFORMANCE)
const val DEFAULT_AUDIO_SOURCE = MediaRecorder.AudioSource.CAMCORDER
val BITRATES = arrayListOf(32000, 64000, 96000, 128000, 160000, 192000, 256000, 320000)
const val DEFAULT_BITRATE = 128000
const val SAMPLE_RATE = 44100
@ -33,6 +43,7 @@ const val TOGGLE_WIDGET_UI = "toggle_widget_ui"
const val HIDE_NOTIFICATION = "hide_notification"
const val SAVE_RECORDINGS = "save_recordings"
const val EXTENSION = "extension"
const val AUDIO_SRC = "audio_source"
const val BITRATE = "bitrate"
const val RECORD_AFTER_LAUNCH = "record_after_launch"

View File

@ -10,7 +10,7 @@ import java.io.FileDescriptor
class MediaRecorderWrapper(val context: Context) : Recorder {
private var recorder = MediaRecorder().apply {
setAudioSource(MediaRecorder.AudioSource.CAMCORDER)
setAudioSource(context.config.audio_source)
setOutputFormat(context.config.getOutputFormat())
setAudioEncoder(context.config.getAudioEncoder())
setAudioEncodingBitRate(context.config.bitrate)

View File

@ -4,7 +4,6 @@ import android.annotation.SuppressLint
import android.content.Context
import android.media.AudioFormat
import android.media.AudioRecord
import android.media.MediaRecorder
import com.naman14.androidlame.AndroidLame
import com.naman14.androidlame.LameBuilder
import com.simplemobiletools.commons.extensions.showErrorToast
@ -33,7 +32,7 @@ class Mp3Recorder(val context: Context) : Recorder {
@SuppressLint("MissingPermission")
private val audioRecord = AudioRecord(
MediaRecorder.AudioSource.CAMCORDER,
context.config.audio_source,
SAMPLE_RATE,
AudioFormat.CHANNEL_IN_MONO,
AudioFormat.ENCODING_PCM_16BIT,

View File

@ -235,6 +235,27 @@
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_audio_source_holder"
style="@style/SettingsHolderTextViewStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ripple_bottom_corners">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_audio_source_label"
style="@style/SettingsTextLabelStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/audio_source" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_audio_source"
style="@style/SettingsTextValueStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/settings_audio_source_label"
tools:text="128 kbps" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_bitrate_holder"
style="@style/SettingsHolderTextViewStyle"

View File

@ -19,12 +19,20 @@
<!-- Settings -->
<string name="try_hiding_notification">Try hiding the recording notification</string>
<string name="save_recordings_in">Save recordings in</string>
<string name="audio_source">Audio Source</string>
<string name="bitrate">Bitrate</string>
<string name="record_after_launch">Start recording automatically after launching the app</string>
<!-- FAQ -->
<string name="faq_1_title">Can I hide the notification icon during recording?</string>
<string name="faq_1_text">Well, it depends. While you use your device it is no longer possible to fully hide the notifications of apps like this.
If you check the proper setting item, the app will do its best to hide it. You can hide it on the lockscreen though, if you disable the displaying of sensitive notifications in your device settings.</string>
<!-- Settings Audio source selection -->
<string name="audio_source_camcorder">Camera (default)</string>
<string name="audio_source_default">Android default</string>
<string name="audio_source_unprocessed">Unprocessed</string>
<string name="audio_source_microphone">Microphone</string>
<string name="audio_source_voice_communication">Voice communication</string>
<string name="audio_source_voice_performance">Voice performance</string>
<!--
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res