0

After updating to Xcode 11.1, the music playback function stopped working. Application stops with error Thread 1: EXC_BAD_ACCESS (code=1, address=0x48)

This is my function that played music and in xcode 10 it works:

func playBackgroundMusic(file: String) {
        do {
            backgroundMusic = try AVAudioPlayer(contentsOf: Bundle.main.url(forResource: file, withExtension: "mp3")!)
            backgroundMusic.numberOfLoops = -1
            backgroundMusic.play()
        } catch {
            print("Can't play music")
        }
    }

maybe someone faced such a problem? I'm tried change mp3 file, but it not helped.

  • 1
    How do you declare your `backgroundMusic` ? – OOPer Oct 10 '19 at 22:25
  • 1
    Check out this answer it might help you: https://stackoverflow.com/questions/58105462/app-crashes-when-playing-audio-on-ios13-1 – mac_eric Oct 11 '19 at 02:02
  • @OOPer thanks for the question, he showed me where to look in the commentator's answer below. Was declared var backgroundMusic = AVAudioPlayer(). I fixed on var backgroundMusic : AVAudioPlayer()! – Alexander Ushakov Oct 19 '19 at 12:17

0 Answers0