INNER CODE UNIT · Swift
extractWaveformFromFile
cometchat/cometchat-uikit-flutter · packages/cometchat_uikit/ios/Classes/SwiftCometchatChatUikitPlugin.swift:556
private func extractWaveformFromFile(filePath: String, sampleCount: Int, completion: @escaping ([Double]) -> Void) {
let fileUrl = URL(fileURLWithPath: filePath)
guard FileManager.default.fileExists(atPath: filePath) else {
completion([])
return
}
DispatchQueue.global(qos: .userInitiated).async {
do {
let audioFile = try AVAudioFile(forReading: fileUrl)
let format = audioFile.processingFormat
let frameCount = UInt32(audioFile.length)
guard frameCount > 0 else {
DispatchQueue.main.async { completion([]) }
return
}