iOS 13.1 Crash in AVAudio Player

我们两清 提交于 2019-11-26 12:46:40

问题


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.


回答1:


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!.




回答2:


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




回答3:


Thanks, Rakesh! It's amazing! My game broke on iPhone with iOS 13.1.2. But in simulator it's work. On physical device - no! I read a lot of forums, online books, docs, etc.

And this small fix really helped me: I changed var player = AVAudioPlayer() to var player: AVAudioPlayer!

p.s. guys wrote about problem with threads but this case is simpler




回答4:


The same issue happens with Objective C code.

Previously musicPlayer = [[AVAudioPlayer alloc] init]; would work but will now cause a crash in iOS13. The crash happens later on when using one of the other init methods like initWithContentsOfURL.

Removing the [[AVAudioPlayer alloc] init] fixes the issue.



来源:https://stackoverflow.com/questions/58110827/ios-13-1-crash-in-avaudio-player

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!