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 com.simplemobiletools.voicerecorder.models.Events
|
||||||
import org.greenrobot.eventbus.EventBus
|
import org.greenrobot.eventbus.EventBus
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.IOException
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class RecorderService : Service() {
|
class RecorderService : Service() {
|
||||||
@ -67,6 +66,7 @@ class RecorderService : Service() {
|
|||||||
if (!defaultFolder.exists()) {
|
if (!defaultFolder.exists()) {
|
||||||
defaultFolder.mkdir()
|
defaultFolder.mkdir()
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultFolder.absolutePath
|
defaultFolder.absolutePath
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,9 +75,18 @@ class RecorderService : Service() {
|
|||||||
setAudioSource(MediaRecorder.AudioSource.CAMCORDER)
|
setAudioSource(MediaRecorder.AudioSource.CAMCORDER)
|
||||||
setOutputFormat(MediaRecorder.OutputFormat.MPEG_4)
|
setOutputFormat(MediaRecorder.OutputFormat.MPEG_4)
|
||||||
setAudioEncoder(MediaRecorder.AudioEncoder.AAC)
|
setAudioEncoder(MediaRecorder.AudioEncoder.AAC)
|
||||||
setOutputFile(currFilePath)
|
|
||||||
|
|
||||||
try {
|
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()
|
prepare()
|
||||||
start()
|
start()
|
||||||
duration = 0
|
duration = 0
|
||||||
@ -89,7 +98,7 @@ class RecorderService : Service() {
|
|||||||
durationTimer.scheduleAtFixedRate(getDurationUpdateTask(), 1000, 1000)
|
durationTimer.scheduleAtFixedRate(getDurationUpdateTask(), 1000, 1000)
|
||||||
|
|
||||||
startAmplitudeUpdates()
|
startAmplitudeUpdates()
|
||||||
} catch (e: IOException) {
|
} catch (e: Exception) {
|
||||||
showErrorToast(e)
|
showErrorToast(e)
|
||||||
stopRecording()
|
stopRecording()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user