Added OPUS codec support (#38)

This commit is contained in:
Agnieszka C 2021-10-03 20:19:16 +02:00
parent 27c1202773
commit 165e06b89c
5 changed files with 21 additions and 4 deletions

View File

@ -10,8 +10,7 @@ import com.simplemobiletools.commons.helpers.isQPlus
import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.voicerecorder.R
import com.simplemobiletools.voicerecorder.extensions.config
import com.simplemobiletools.voicerecorder.helpers.EXTENSION_M4A
import com.simplemobiletools.voicerecorder.helpers.EXTENSION_MP3
import com.simplemobiletools.voicerecorder.helpers.*
import kotlinx.android.synthetic.main.activity_settings.*
import java.util.*
@ -101,6 +100,10 @@ class SettingsActivity : SimpleActivity() {
RadioItem(EXTENSION_M4A, getString(R.string.m4a)),
RadioItem(EXTENSION_MP3, getString(R.string.mp3)))
if (isQPlus()) {
items.add(RadioItem(EXTENSION_OGG, getString(R.string.ogg)))
}
RadioGroupDialog(this@SettingsActivity, items, config.extension) {
config.extension = it as Int
settings_extension.text = config.getExtensionText()

View File

@ -1,6 +1,7 @@
package com.simplemobiletools.voicerecorder.helpers
import android.content.Context
import android.media.MediaRecorder
import com.simplemobiletools.commons.helpers.BaseConfig
import com.simplemobiletools.voicerecorder.R
@ -23,6 +24,17 @@ class Config(context: Context) : BaseConfig(context) {
fun getExtensionText() = context.getString(when (extension) {
EXTENSION_M4A -> R.string.m4a
EXTENSION_OGG -> R.string.ogg
else -> R.string.mp3
})
fun getOutputFormat() = when (extension) {
EXTENSION_OGG -> MediaRecorder.OutputFormat.OGG
else -> MediaRecorder.OutputFormat.MPEG_4
}
fun getAudioEncoder() = when (extension) {
EXTENSION_OGG -> MediaRecorder.AudioEncoder.OPUS
else -> MediaRecorder.AudioEncoder.AAC
}
}

View File

@ -16,6 +16,7 @@ const val TOGGLE_PAUSE = PATH + "TOGGLE_PAUSE"
const val EXTENSION_M4A = 0
const val EXTENSION_MP3 = 1
const val EXTENSION_OGG = 2
const val RECORDING_RUNNING = 0
const val RECORDING_STOPPED = 1

View File

@ -74,8 +74,8 @@ class RecorderService : Service() {
currFilePath = "$baseFolder/${getCurrentFormattedDateTime()}.${config.getExtensionText()}"
recorder = MediaRecorder().apply {
setAudioSource(MediaRecorder.AudioSource.CAMCORDER)
setOutputFormat(MediaRecorder.OutputFormat.MPEG_4)
setAudioEncoder(MediaRecorder.AudioEncoder.AAC)
setOutputFormat(config.getOutputFormat())
setAudioEncoder(config.getAudioEncoder())
setAudioEncodingBitRate(128000)
setAudioSamplingRate(44100)

View File

@ -3,5 +3,6 @@
<string name="package_name">com.simplemobiletools.voicerecorder</string>
<string name="m4a">m4a</string>
<string name="mp3">mp3</string>
<string name="ogg">ogg</string>
</resources>