简体   繁体   English

AVAudioPlayer失败,并显示错误“操作无法完成。 (OSStatus错误2003334207。)”

[英]AVAudioPlayer fails with error “The operation couldn’t be completed. (OSStatus error 2003334207.)”

This is my code sample... for few audio files (mp4 extension) it fails with exception "The operation couldn't be completed. (OSStatus error 2003334207.)" I downloaded container from iPhone and confirmed the file exist on path 这是我的代码示例...对于少数音频文件(mp4扩展名),它会失败,但出现异常“操作无法完成。(OSStatus错误2003334207。)”。我从iPhone下载了容器,并确认文件存在于路径中

do {  

    audioPlayer = try AVAudioPlayer(contentsOf: url)

     //guard let player = player else { return }
     audioPlayer.delegate = self
     audioPlayer.prepareToPlay()
     audioPlayer.play()
     audioPlayer.volume = 1.0

     if timer != nil && timer.isValid {
         timer.invalidate()
         timer = nil
     }

     timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(LynkAudioPlayer.checkPlayTime), userInfo: nil, repeats: true)

} catch let error as NSError {
     print(error.description)
}

Your code looks fine. 您的代码看起来不错。 This error occurs because you are either accessing a file that is not at the specified url or the value is otherwise nil after it returns. 发生此错误的原因是,您正在访问的文件不在指定的url或者返回的值是nil Ensure you have a properly formed url for the resource accessed with AVAudioPlayer(contentsOf: url) . 确保您具有使用AVAudioPlayer(contentsOf: url)访问的资源的AVAudioPlayer(contentsOf: url)正确的AVAudioPlayer(contentsOf: url) The audio data must also be in a format supported by Core Audio. 音频数据还必须采用Core Audio支持的格式。 You may want to check if audioPlayer is nil after setting: 设置后,您可能要检查audioPlayer是否为nil

audioPlayer = try AVAudioPlayer(contentsOf: url)

if audioPlayer != nil { 
    audioPlayer.delegate = self
    audioPlayer.prepareToPlay()
    audioPlayer.play()
    audioPlayer.volume = 1.0
} else {
    //try to load a different resource?
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 操作无法完成。 (OSStatus 错误 2003334207。) - The Operation Couldn’t Be Completed. (OSStatus Error 2003334207.) 音频播放器错误:操作无法完成。 (OSStatus 错误 2003334207。) - audioPlayer error: The operation couldn’t be completed. (OSStatus error 2003334207.) iOS 5.0 AVAudioPlayer加载音频片段时出错:无法完成该操作。 (OSStatus错误-50。) - iOS 5.0 AVAudioPlayer Error loading audio clip: The operation couldn’t be completed. (OSStatus error -50.) 该操作无法完成。 (OSStatus错误-10827。) - The operation couldn’t be completed. (OSStatus error -10827.) MidiClientCreate“操作无法完成。 (OSStatus错误-50。)” - MidiClientCreate “The operation couldn't be completed. (OSStatus error -50.)” 操作无法完成。 (OSStatus 错误 -54。) - The operation couldn’t be completed. (OSStatus error -54.) -canOpenURL:URL 失败:“fbauth2:/” - 错误:“操作无法完成。(OSStatus 错误 -10814。) - -canOpenURL: failed for URL: "fbauth2:/" - error: "The operation couldn’t be completed. (OSStatus error -10814.) SKSMTPMessage错误-无法完成该操作。(OSStatus错误-9807。) - SKSMTPMessage Error- The operation couldn't be completed.(OSStatus error -9807.) 操作无法完成。 (OSStatus 错误 -600。)无法在模拟器中运行应用程序 - The operation couldn’t be completed. (OSStatus error -600.) Cant run app in simulator “comgooglemaps://” - 错误:“操作无法完成。 (OSStatus错误-10814。)“ - “comgooglemaps://” - error: “The operation couldn’t be completed. (OSStatus error -10814.)”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM