App crashes with the following error message
2019-10-12 20:01:34.332334-0700 Awesome App[26368:3535170] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x600002903280> F8BB1C28-BAE8-11D6-9C31-00039315CD46
The breakpoint at crash seems to be related to AVAudioPlayer
let path = Bundle.main.path(forResource: "menu_background.mp3", ofType:nil)!
audioPlayer = try AwesomeAudioPlayer(contentsOf: URL(fileURLWithPath: path)) ---> breakpoint
I believe you all might have added the AVFoundation to the frameworks list in Project General Info tab.
Erroneous Code was as follows:
And after I moved the
var audioPlayer: AVAudioPlayer
declaration to just after the line ofimport AVFoundation
line it seemed to be working.So following code worked for me in a
SwiftUI
project.}
I was initially following this tutorial of CodeWithChris and its discussion also led to above change. Also checkout following tutorial too if you need further examples.
Hope this will be helpful to someone of you out there!
Cheers!
I believe the error message is a warning for simulators hence it is not important.
I think your issue is a bug in your code. Should be something like this:
let path = Bundle.main.path(forResource: "menu_background", ofType:"mp3") audioPlayer = try AwesomeAudioPlayer(contentsOf: URL(fileURLWithPath: path!)) ---> breakpoint
Where the forResource is the name of the file and ofType is the extension. You can also use Bundle.main.url which will look like this:
let path = Bundle.main.url(forResource: "menu_background", withExtension:"mp3") audioPlayer = try AwesomeAudioPlayer(contentsOf: URL(fileURLWithPath: path!)) ---> breakpoint
I have found the solution in another stackoverflow thread about AVAudioPlayer, here it is :
If you initialize your
AVAudioPlayer
likevar wrongMusicPlayer: AVAudioPlayer = AVAudioPlayer()
ORwrongMusicPlayer = AVAudioPlayer()
in any method then please remove it and just Declare likevar wrongMusicPlayer: AVAudioPlayer
!.You could use do/catch to avoid the crash and examine the exception, or ignore the issue all together with
try?
. For me, this was only showing up in the simulator when calling:try? AVAudioSession.sharedInstance().setCategory(.playback)
I think it's safe to ignore it in my case.