iOS 13.1 Crash in AVAudio Player

前端 未结 4 2009
盖世英雄少女心
盖世英雄少女心 2020-11-29 10:26

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 le         


        
相关标签:
4条回答
  • 2020-11-29 10:33

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

    0 讨论(0)
  • 2020-11-29 10:38

    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

    0 讨论(0)
  • 2020-11-29 10:48

    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.

    0 讨论(0)
  • 2020-11-29 10:49

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

    0 讨论(0)
提交回复
热议问题