首页 > 解决方案 > OSStatus 错误 2003334207 AVAudioPlayer

问题描述

我正在尝试播放从 iTunes API 获得的音频 url。它们是 m4a 类型。我将 URL 保存为字符串并将其发送到我的 playSound 函数。我查看了其他有此错误的帖子,但无法修复我的。

示例音频网址

https://audio-ssl.itunes.apple.com/apple-assets-us-std-000001/Music1/v4/fd/4b/f9/fd4bf91e-2a1d-a946-a2f5-2d828da0f8e5/mzaf_2707169172634594413.plus.aac。 p.m4a

我收到错误“错误:无法完成操作。(OSStatus 错误 2003334207。)”

func playSound(soundUrl: String) {
    let sound = NSURL(fileURLWithPath: soundUrl)
    do {
        let audioPlayer = try AVAudioPlayer(contentsOf: sound as URL)
        audioPlayer.delegate = self as? AVAudioPlayerDelegate
        audioPlayer.prepareToPlay()
        audioPlayer.play()
    }catch let error {
        print("Error: \(error.localizedDescription)")
    }
}

标签: iosswiftavfoundationavaudioplayer

解决方案


推荐阅读