Trying play AMR audio file using this code:
var player: AVAudioPlayer? = nil
WebService.shared.download(self.dataSource.object(at: indexPath)) { data in
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
try AVAudioSession.sharedInstance().setActive(true)
player = try AVAudioPlayer(data: data, fileTypeHint: AVFileType.amr.rawValue)
guard let player = player else { return }
print("Going to play: \(player.duration) seconds...")
player.volume = 1.0
player.prepareToPlay()
player.play()
} catch {
print(error.localizedDescription)
}
}
I'm absolutely sure that:
- data received is not nil
- I can see correct duration time of amr file
- amr files contains some voices
- I did not get any error's
- I did not hear anything
What's up and how fix it?