Is anyone else getting this console message with AVAudioPlayer in Xcode 11 (and 11.1)?

我的梦境 提交于 2021-01-01 07:03:07

问题


I have a simple example program with AVAudioPlayer and am getting this message when I run it. This occurs before .play() is called:

2019-10-08 12:34:53.093726+1100 PlayNotes2[1587:137643] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x600000c580e0> F8BB1C28-BAE8-11D6-9C31-00039315CD46

The program works fine, but I'm concerned to be getting this message.

Here is my complete code. It just has one button on the view with the playButtonTap outlet. Note that the same thing happens if I use the commented out declaration for var audioPlayer.

import UIKit
import AVFoundation

class ViewController: UIViewController {

    let soundFileName = "E_64kb"

    //  var audioPlayer = AVAudioPlayer()
    var audioPlayer: AVAudioPlayer?

    override func viewDidLoad() {
        super.viewDidLoad()

        let sound = Bundle.main.path(forResource: soundFileName, ofType: "mp3")
        do {
             audioPlayer = try AVAudioPlayer(contentsOf: URL(fileURLWithPath: sound!))
        } catch {
            print(error)
        }
    }

    @IBAction func playButtonTap(_ sender: Any) {
        audioPlayer!.play()
    } 
}

回答1:


The warning is unimportant. If you really object to it, run the app on a device instead of in a simulator. The console message will go away.




回答2:


I'm on xcode 12 macos-bigsur.

I have just got this message while im working on a MacOS app. It is definetly about AVFoundation framework. Because i have just managed to play a tiny .wav file with AudioToolbox without that warning:

Here is that code:

import Cocoa
import AudioToolbox


class ViewController: NSViewController
{   
    override func viewDidLoad()
    {
        super.viewDidLoad()
    }
    
    override func viewWillAppear()
    {
        let path = Bundle.main.path(forResource: "wr", ofType: "wav")!
        let url = URL(fileURLWithPath: path)
        var soundID : SystemSoundID = 4543523
        let cfURL = CFURLCreateWithString(kCFAllocatorDefault, url.absoluteString as CFString, nil)
        AudioServicesCreateSystemSoundID(cfURL!, &soundID)
        AudioServicesPlaySystemSound(soundID)
    }

}

This code creates a system sound from wr.wav file and plays that sound without any warning. I think this proves that this warning will go away once apple updates xcode or bigsur. So i will ignore that warning and continue using AVAudioPlayer

!!IMPORTANT do not use this code for production. It is low level C code, i don't know if it's leaking and it's also very limiting. Here read this documentation:

Sound files that you play using this function must be: No longer than 30 seconds in duration. In linear PCM or IMA4 (IMA/ADPCM) format. Packaged in a .caf, .aif, or .wav file.

In addition, when you use the AudioServicesPlaySystemSound function: Sounds play at the current system audio volume, with no programmatic volume control available. Sounds play immediately. Looping and stereo positioning are unavailable. Simultaneous playback is unavailable: You can play only one sound at a time. The sound is played locally on the device speakers; it does not use audio routing.




回答3:


I got the same error and found that the sound file path was nil.




回答4:


You can try something like this:

import UIKit
import AVFoundation
class abdicateDef: UIViewController {

    var playabdicatesound = URL(fileURLWithPath: Bundle.main.path(forResource: "abdicatesound", ofType: "wav")!)

    var playerabdicatesound = AVAudioPlayer()

    @IBOutlet weak var popupDef: UIView!

    override func viewDidLoad() {
        super.viewDidLoad()

        popupDef.layer.cornerRadius = 10
        popupDef.layer.masksToBounds = true

        //Getting error on this line of code Thread 1: EXC_BAD_ACCESS (code=1, address=0x48)
        playerabdicatesound = try! AVAudioPlayer(contentsOf: playabdicatesound, fileTypeHint: nil)

    }
    @IBAction func backButton(_ sender: Any) {
        dismiss(animated: true, completion: nil)

    }
    @IBAction func soundButton(_ sender: Any) {
        playerabdicatesound.play()
    }

}


来源:https://stackoverflow.com/questions/58279150/is-anyone-else-getting-this-console-message-with-avaudioplayer-in-xcode-11-and

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