Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.5k views
in Technique[技术] by (71.8m points)

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...