Восстановлены голосовые
This commit is contained in:
@@ -10,25 +10,39 @@ class VoiceRecorder(private val context: Context) {
|
||||
private var recorder: MediaRecorder? = null
|
||||
|
||||
fun startRecording(outputFile: File) {
|
||||
recorder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
MediaRecorder(context)
|
||||
} else {
|
||||
MediaRecorder()
|
||||
}.apply {
|
||||
setAudioSource(MediaRecorder.AudioSource.MIC)
|
||||
setOutputFormat(MediaRecorder.OutputFormat.MPEG_4)
|
||||
setAudioEncoder(MediaRecorder.AudioEncoder.AAC)
|
||||
setOutputFile(FileOutputStream(outputFile).fd)
|
||||
prepare()
|
||||
start()
|
||||
try {
|
||||
android.util.Log.d("VoiceRecorder", "startRecording to ${outputFile.absolutePath}")
|
||||
recorder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
MediaRecorder(context)
|
||||
} else {
|
||||
MediaRecorder()
|
||||
}.apply {
|
||||
setAudioSource(MediaRecorder.AudioSource.MIC)
|
||||
setOutputFormat(MediaRecorder.OutputFormat.MPEG_4)
|
||||
setAudioEncoder(MediaRecorder.AudioEncoder.AAC)
|
||||
setOutputFile(FileOutputStream(outputFile).fd)
|
||||
prepare()
|
||||
start()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
android.util.Log.e("VoiceRecorder", "Failed to start recording", e)
|
||||
recorder?.release()
|
||||
recorder = null
|
||||
}
|
||||
}
|
||||
|
||||
fun stopRecording() {
|
||||
recorder?.apply {
|
||||
stop()
|
||||
release()
|
||||
try {
|
||||
android.util.Log.d("VoiceRecorder", "stopRecording")
|
||||
recorder?.let {
|
||||
it.stop()
|
||||
it.release()
|
||||
android.util.Log.d("VoiceRecorder", "stopRecording success")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
android.util.Log.e("VoiceRecorder", "Failed to stop recording", e)
|
||||
} finally {
|
||||
recorder = null
|
||||
}
|
||||
recorder = null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user