this piece of code worked for me fine
func playAudio(){ let audioUrl = URL(fileURLWithPath: value, relativeTo: someBasePath) do{ try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback) try AVAudioSession.sharedInstance().setActive(true) audioPlayer = try AVAudioPlayer(contentsOf: audioUrl, fileTypeHint: AVFileTypeMPEGLayer3) audioPlayer.prepareToPlay() audioPlayer.play() }catch{ print(error.localizedDescription) }}
and you have to define audioPlayer
as a class member or it goes out of scope otherwise and it won't work.
var audioPlayer: AVAudioPlayer!
thats it