diff --git a/vector/src/main/java/im/vector/app/features/voice/AbstractVoiceRecorder.kt b/vector/src/main/java/im/vector/app/features/voice/AbstractVoiceRecorder.kt index 8a0f829f94..794130d528 100644 --- a/vector/src/main/java/im/vector/app/features/voice/AbstractVoiceRecorder.kt +++ b/vector/src/main/java/im/vector/app/features/voice/AbstractVoiceRecorder.kt @@ -26,17 +26,17 @@ abstract class AbstractVoiceRecorder( context: Context, private val filenameExt: String ) : VoiceRecorder { - private val outputDirectory = File(context.cacheDir, "voice_records") + private val outputDirectory: File by lazy { + File(context.cacheDir, "voice_records").also { + if (!it.exists()) { + it.mkdirs() + } + } + } private var mediaRecorder: MediaRecorder? = null private var outputFile: File? = null - init { - if (!outputDirectory.exists()) { - outputDirectory.mkdirs() - } - } - abstract fun setOutputFormat(mediaRecorder: MediaRecorder) abstract fun convertFile(recordedFile: File?): File? diff --git a/vector/src/main/java/im/vector/app/features/voice/VoicePlayerHelper.kt b/vector/src/main/java/im/vector/app/features/voice/VoicePlayerHelper.kt index f1b316c456..64b06a72f8 100644 --- a/vector/src/main/java/im/vector/app/features/voice/VoicePlayerHelper.kt +++ b/vector/src/main/java/im/vector/app/features/voice/VoicePlayerHelper.kt @@ -27,11 +27,11 @@ import javax.inject.Inject class VoicePlayerHelper @Inject constructor( context: Context ) { - private val outputDirectory = File(context.cacheDir, "voice_records") - - init { - if (!outputDirectory.exists()) { - outputDirectory.mkdirs() + private val outputDirectory: File by lazy { + File(context.cacheDir, "voice_records").also { + if (!it.exists()) { + it.mkdirs() + } } }