Skip to content

Commit

Permalink
element-hq/element-ios/issues/4753 - Prevent unnecessary audio file c…
Browse files Browse the repository at this point in the history
…onversions if final file already exists on disk.
  • Loading branch information
stefanceriu authored and Philippe Loriaux committed Jan 14, 2022
1 parent bf84737 commit 75ceeb1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ class VoiceMessageAttachmentCacheManager {
return
}

let newURL = temporaryFilesFolderURL.appendingPathComponent(ProcessInfo().globallyUniqueString).appendingPathExtension("m4a")
let newURL = temporaryFilesFolderURL.appendingPathComponent(identifier).appendingPathExtension("m4a")

VoiceMessageAudioConverter.convertToMPEG4AAC(sourceURL: URL(fileURLWithPath: filePath), destinationURL: newURL) { result in
let conversionCompletion: (Result<Void, VoiceMessageAudioConverterError>) -> Void = { result in
self.workQueue.async {
switch result {
case .success:
Expand Down Expand Up @@ -245,6 +245,12 @@ class VoiceMessageAttachmentCacheManager {
}
}
}

if FileManager.default.fileExists(atPath: newURL.path) {
conversionCompletion(Result.success(()))
} else {
VoiceMessageAudioConverter.convertToMPEG4AAC(sourceURL: URL(fileURLWithPath: filePath), destinationURL: newURL, completion: conversionCompletion)
}
}

private func sampleFileAtURL(_ url: URL, duration: TimeInterval, numberOfSamples: Int, identifier: String, semaphore: DispatchSemaphore) {
Expand Down
2 changes: 1 addition & 1 deletion changelog.d/4753.feature
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Allow audio file attachments to be played back inline by reusing the existing voice message UI.
Allow audio file attachments to be played back inline by reusing the existing voice message UI. Prevent unnecessary conversions if final file already exists on disk.

0 comments on commit 75ceeb1

Please sign in to comment.