mirror of
https://github.com/SimpleMobileTools/Simple-Voice-Recorder.git
synced 2025-06-05 21:59:31 +02:00
properly handle saving recordings on SD cards
This commit is contained in:
@ -26,7 +26,6 @@ import com.simplemobiletools.voicerecorder.helpers.STOP_AMPLITUDE_UPDATE
|
||||
import com.simplemobiletools.voicerecorder.models.Events
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
|
||||
class RecorderService : Service() {
|
||||
@ -67,6 +66,7 @@ class RecorderService : Service() {
|
||||
if (!defaultFolder.exists()) {
|
||||
defaultFolder.mkdir()
|
||||
}
|
||||
|
||||
defaultFolder.absolutePath
|
||||
}
|
||||
|
||||
@ -75,9 +75,18 @@ class RecorderService : Service() {
|
||||
setAudioSource(MediaRecorder.AudioSource.CAMCORDER)
|
||||
setOutputFormat(MediaRecorder.OutputFormat.MPEG_4)
|
||||
setAudioEncoder(MediaRecorder.AudioEncoder.AAC)
|
||||
setOutputFile(currFilePath)
|
||||
|
||||
try {
|
||||
if (!isQPlus() && isPathOnSD(currFilePath)) {
|
||||
var document = getDocumentFile(currFilePath.getParentPath())
|
||||
document = document?.createFile("", currFilePath.substring(currFilePath.lastIndexOf('/') + 1))
|
||||
|
||||
val outputFileDescriptor = contentResolver.openFileDescriptor(document!!.uri, "w")!!.fileDescriptor
|
||||
setOutputFile(outputFileDescriptor)
|
||||
} else {
|
||||
setOutputFile(currFilePath)
|
||||
}
|
||||
|
||||
prepare()
|
||||
start()
|
||||
duration = 0
|
||||
@ -89,7 +98,7 @@ class RecorderService : Service() {
|
||||
durationTimer.scheduleAtFixedRate(getDurationUpdateTask(), 1000, 1000)
|
||||
|
||||
startAmplitudeUpdates()
|
||||
} catch (e: IOException) {
|
||||
} catch (e: Exception) {
|
||||
showErrorToast(e)
|
||||
stopRecording()
|
||||
}
|
||||
|
Reference in New Issue
Block a user