Fix some voice message issues (#7325, #7217)

Fix #7325: prevent setting the audio session to inactive during recording
Fix #7217: ensure that an audio player has its content loaded when it reaches the end to allow seek and replay.
This commit is contained in:
Nicolas Mauri
2023-02-09 11:50:11 +01:00
parent e89f773e92
commit 8ee26ab378
7 changed files with 58 additions and 10 deletions
@@ -73,15 +73,18 @@ class VoiceMessageAudioRecorder: NSObject, AVAudioRecorderDelegate {
}
}
func stopRecording() {
func stopRecording(releaseAudioSession: Bool = true) {
audioRecorder?.stop()
do {
try AVAudioSession.sharedInstance().setActive(false)
} catch {
delegateContainer.notifyDelegatesWithBlock { delegate in
(delegate as? VoiceMessageAudioRecorderDelegate)?.audioRecorder(self, didFailWithError: VoiceMessageAudioRecorderError.genericError) }
if releaseAudioSession {
MXLog.debug("[VoiceMessageAudioRecorder] stopRecording() - releasing audio session")
do {
try AVAudioSession.sharedInstance().setActive(false)
} catch {
delegateContainer.notifyDelegatesWithBlock { delegate in
(delegate as? VoiceMessageAudioRecorderDelegate)?.audioRecorder(self, didFailWithError: VoiceMessageAudioRecorderError.genericError) }
}
}
}
func peakPowerForChannelNumber(_ channelNumber: Int) -> Float {