Re-Assigning Instance of Avaudioplayer in iOS13 Leads to Bad_Access Runtime Error

Re-Assigning instance of AVAudioPlayer in iOS13 leads to BAD_ACCESS runtime error

Just remove the initialisation and it will work

private var mySoundPlayer: AVAudioPlayer!

Cheers!!!

Can't play local mp3 above ios13 swift

Looks like a duplicate of 58166133.

AVAudioPlayer doesn't have an init so you should update your first line, like this

var MediaPlayer: AVAudioPlayer!

Release AVAudioPlayer in iOS4/iOS5 giving EXC_BAD_ACCESS error

Thanks to the comment above, and the failure of all my other ideas, I went ahead and took advantage of ARC.

I didn't want to refactor my entire project to start using ARC, so I rewrote a new class to handle all of my audio needs and set some compiler flags (-fobjc-arc) to enable ARC just for that file.

Not exactly sure what I was doing wrong before, but the system seems to be much better at managing memory than I am, and I'm happy to let it solve all my problems.

EDIT 2:

Apparently Apple did finally fix their memory leak so I went back to my ARC solution which works fine for both iOS 5 and iOS 6.

EDIT:

I may have been a little premature.

While implementing ARC for this was helpful in general, this specific problem goes deeper.

Apparently, there is a leak in Core Foundation for iOS 6.

Leak from NSURL and AVAudioPlayer using ARC

Memory Leak - NSString & NSURL

Using ARC, it works fine on my Gen 3 iOS 5 device, but leaks significantly for Gen 4/5 iOS 6.

Without ARC, Gen 4/5 iOS 6 works fine, but Gen 3 iOS 5 crashes.

I ended up making two versions of my new class, one using ARC and one not, and checking the system version at runtime [[UIDevice currentDevice] systemVersion] to determine which version to use.

It may be a little clumsy, but does allow me to support the Gen 3 devices. If Apple ever fixes their problem I can return to a single version at that time.

AVAudioPlayer refuses to play anything, but no error, etc

Turned out it was an issue with ARC releasing, I fixed it by adding a @property and @synthesize pair for the AVAudioPlayer in question, and declaring it as strong. It got rid of all of these errors, and played the file with no problems.



Related Topics



Leave a reply



Submit