Swift 5.1 Error: [plugin] AddInstanceForFactory: No factory registered for id <CFUUID

Amar Kanala picture Amar Kanala · Oct 13, 2019 · Viewed 23.1k times · Source

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

Answer

Randika Vishman picture Randika Vishman · Apr 10, 2020

I believe you all might have added the AVFoundation to the frameworks list in Project General Info tab.

Erroneous Code was as follows:

import SwiftUI
import AVFoundation

struct PlayerDetailView: View {
@State private var downloadedFilePath: URL = nil
var audioPlayer: AVAudioPlayer
 
var body: some View {

And after I moved the var audioPlayer: AVAudioPlayer declaration to just after the line of import AVFoundation line it seemed to be working.

So following code worked for me in a SwiftUI project:

import SwiftUI
import AVFoundation
var audioPlayer: AVAudioPlayer!

struct PlayerDetailView: View {
@State private var downloadedFilePath: URL = nil
 
var body: some View {
    VStack {
        Button("Play the Downloaded Track") {
            if let downloadedPath = self.downloadedFilePath?.path, FileManager().fileExists(atPath: downloadedPath) {
                do {
                    audioPlayer = try AVAudioPlayer(contentsOf: self.downloadedFilePath!)
                    guard let player = audioPlayer else { return }
                    
                    player.prepareToPlay()
                    player.play()
                } catch let error {
                    print(error.localizedDescription)
                }
            } else {
                print("The file doesn not exist at path || may not have been downloaded yet")
            }
        }
    }
}

}

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!