I am trying to pause the AVAudioPlayer
if it is currently playing. When I debug my code and check AVAudioPlayer
, I see it is allocated. When I try to access a method/property on it (i.e. myAudioPlayer isPlaying
), I get an EXC_BAD_ACCESS
error. This happens if the AVAudioPlayer
does not have a sound loaded. Is there a way I can do a check to see if it has loaded a sound? I tried accessing myAudioPlayer.data
, but I still get the same error.
For me it was because I wasn't calling the one of the designated initialisers. I was instantiating it with AVAudioPlayer()
instead of the designated initialisers which are public init(contentsOfURL url: NSURL) throws
and public init(data: NSData) throws
As of iOS 13, make sure you are removing the initialization on AVAudioPlayer before asigning it with AVAudioPlayer(contentsOf: URL(...))
i.e. change
var audioPlayer = AudioPlayer()
to var audioPlayer: AVAudioPlayer!
I guess you have to use prepareToPlay method to find whether it has loaded or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With