i'm trying to play audio file from bundle (from project) and its should be silent when user set silent mode of device. my code is here
let audioSession = AVAudioSession.sharedInstance()
ringURl = Bundle.main.url(forResource: "ring", withExtension: "m4r")
do {
try audioSession.setCategory(AVAudioSessionCategorySoloAmbient)
try audioSession.overrideOutputAudioPort(speakerType)
}
do {
player = try AVAudioPlayer(contentsOf: ringURl)
guard let player = player else { return }
player?.prepareToPlay()
player?.play()
} catch let error as NSError {
print(error.description)
}
} catch let error as NSError {
print("audioSession error: \(error.localizedDescription)")
}
but its show
audioSession error: The operation couldn’t be completed. (OSStatus error -50.)
error and not working. pls help.