Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 13.1 Crash in AVAudio Player

My App is crashing on iOS 13.1 when i trace a issue then found App is crashing because of AVAudioPlayer.

Below Is My Player Setup.

if let wrongURL = Bundle.main.url(forResource: "wrongAudio", withExtension: "mp3")
        {
            do {
                wrongMusicPlayer = try AVAudioPlayer(contentsOf: wrongURL)
                wrongMusicPlayer.prepareToPlay()
            }
            catch
            {
                print(error.localizedDescription)
            }
        }

Here All things found correctly but crash when AVAudioPlayer try to initialise with URL.

like image 830
Rakesh Patel Avatar asked Sep 26 '19 06:09

Rakesh Patel


2 Answers

I found a crash issue in AVAudioPlayer with iOS 13.1.

Here Is Solution

Why My AVAudioPlayer crash? because

I initialise AVAudioPlayer like

var wrongMusicPlayer: AVAudioPlayer = AVAudioPlayer()

and then i try to reassign wrongMusicPlayer as below

wrongMusicPlayer = try AVAudioPlayer(contentsOf: wrongURL)

And my app get crash.

Solution

If you initialise your AVAudioPlayer like var wrongMusicPlayer: AVAudioPlayer = AVAudioPlayer() OR wrongMusicPlayer = AVAudioPlayer() in any method then please remove it and just Declare like var wrongMusicPlayer: AVAudioPlayer!.

like image 65
Rakesh Patel Avatar answered Sep 23 '22 03:09

Rakesh Patel


iOS 13.2, which be released today, fixes this issue.

like image 31
Andreas Stokidis Avatar answered Sep 23 '22 03:09

Andreas Stokidis