如何消除这些 AVAudioPlayer 消息/错误?

发布于 2025-01-10 06:04:43 字数 2436 浏览 0 评论 0原文

使用 AVFoundation 的 AVAudioPlayer 时,我遇到一些控制台消息/错误。

第一个问题是在调用 AVAudioPlayer 实例上的prepareToPlay()方法后,控制台中立即出现两条消息。

'2022-02-26 15:10:46.372023-0600 TestApp[11705:5688753] [插件] AddInstanceForFactory:没有为 id注册工厂F8BB1C28-BAE8-11D6-9C31-00039315CD46'

'2022-02-26 15:10:46.416502-0600 TestApp[11705:5688753] 未找到保存的启用硬件采样率转换器首选项'

上述消息仅在第一次调用prepareToPlay()时出现实例化 AVAudioPlayer 实例后。

第二个问题是当在 AVAudioPlayer 实例上调用 play() 方法时,控制台中会出现以下消息。

'2022-02-26 15:13:53.005976-0600 TestApp[11731:5691158] [aqme] MEMixerChannel.cpp:1639 client发送格式信息时出现错误 2003332927'

每次在实例化的 AVAudioPlayer 实例上调用 play() 方法以及播放成功结束时,都会出现此消息。

下面是一个简短的示例:

import Cocoa
import AVFAudio

class ViewController: NSViewController, AVAudioPlayerDelegate {

    var player: AVAudioPlayer?
    var trackNumber = 0

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        startTimer()
    }
    
    @objc func timerMethod() {
        playAudioFile(url: URL(fileURLWithPath: "/Users/Shared/Sounds/countdown.mp3"))
    }
    
    func startTimer() {
        let _ = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(timerMethod), userInfo: nil, repeats: false)
    }

    func playAudioFile(url: URL) {
        player = try! AVAudioPlayer(contentsOf: url)
        player?.delegate = self
        player?.prepareToPlay()
        player?.play()
    }

    @objc func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully: Bool) {
        if trackNumber == 0 {
            playAudioFile(url: URL(fileURLWithPath: "/Users/Shared/Sounds/implode.mp3"))
            trackNumber += 1
        }
    }
}

我的环境是 Xcode 13.2.1/Swift 5.5.2 和 macOS 12.2.1,在 2015 年末的 Intel iMac 上运行。

作为参考,我通读了这些答案。前两个适用于 iOS,Apple 论坛似乎适用于 macOS。他们都没有适合我的解决方案。

  1. iOS 1
  2. iOS 2
  3. 苹果论坛

I'm encountering a couple of console messages/error when using AVAudioPlayer from AVFoundation.

The first issue is two messages appearing in the console immediately upon calling the prepareToPlay() method on an AVAudioPlayer instance.

'2022-02-26 15:10:46.372023-0600 TestApp[11705:5688753] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x6000039488a0> F8BB1C28-BAE8-11D6-9C31-00039315CD46'

'2022-02-26 15:10:46.416502-0600 TestApp[11705:5688753] no saved enable hardware sample rate converter preference found'

This above messages only appear the first time prepareToPlay() is called after an AVAudioPlayer instance is instantiated.

The second issue is the following message appears in the console when the play() method is called on an AVAudioPlayer instance.

'2022-02-26 15:13:53.005976-0600 TestApp[11731:5691158] [aqme] MEMixerChannel.cpp:1639 client <AudioQueueObject@0x7ff03d824600; [0]; play> got error 2003332927 while sending format information'

This message appears every time the play() method is called on an instantiated AVAudioPlayer instance and when the play ends successfully.

Here is a short example:

import Cocoa
import AVFAudio

class ViewController: NSViewController, AVAudioPlayerDelegate {

    var player: AVAudioPlayer?
    var trackNumber = 0

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        startTimer()
    }
    
    @objc func timerMethod() {
        playAudioFile(url: URL(fileURLWithPath: "/Users/Shared/Sounds/countdown.mp3"))
    }
    
    func startTimer() {
        let _ = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(timerMethod), userInfo: nil, repeats: false)
    }

    func playAudioFile(url: URL) {
        player = try! AVAudioPlayer(contentsOf: url)
        player?.delegate = self
        player?.prepareToPlay()
        player?.play()
    }

    @objc func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully: Bool) {
        if trackNumber == 0 {
            playAudioFile(url: URL(fileURLWithPath: "/Users/Shared/Sounds/implode.mp3"))
            trackNumber += 1
        }
    }
}

My environment is Xcode 13.2.1/Swift 5.5.2 and macOS 12.2.1 running on a late 2015 Intel iMac.

For reference I read through these answers. The first two are for iOS, and it appears the Apple Forum is for macOS. None of them have a solution that works for me.

  1. iOS 1
  2. iOS 2
  3. Apple Forum

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文