小编Per*_*tum的帖子

Swift:必需条件为false:file!= nil

该应用程序运行正常,但一旦我点击chipmunkBut​​ton应用程序崩溃并提供以下错误:

错误:AVAudioPlayerNode.mm:678: - [AVAudioPlayerNode scheduleFile:atTime:completionHandler:]:必需条件为false:file!= nil 2015-05-10 17:24:25.269 Pitch Perfect [50278:1897012]***终止app由于未被捕获的异常'com.apple.coreaudio.avfaudio',原因:'必要条件为false:file!= nil'

import UIKit
import AVFoundation

class PlaySoundsViewController: UIViewController {

    var audioRecording = AVAudioPlayer()
    var receivedAudio:RecordedAudio!
    var audioEngine:AVAudioEngine!
    var audioFile:AVAudioFile!



    func setupAudioPlayerWithFile(file:NSString, type:NSString) -> AVAudioPlayer  {


        //1
        var path = NSBundle.mainBundle().pathForResource(file as String, ofType: type as String)
        var url = NSURL.fileURLWithPath(path!)

        //2
        var error: NSError?

        //3
        var audioPlayer:AVAudioPlayer?
        audioPlayer = AVAudioPlayer(contentsOfURL: url, error: &error)

        //4
        return audioPlayer!
    }


    override func viewDidLoad() {
        super.viewDidLoad()


        audioRecording = AVAudioPlayer(contentsOfURL: receivedAudio.filePathUrl, error: nil)
        audioRecording.enableRate …
Run Code Online (Sandbox Code Playgroud)

null ios swift avaudioengine avaudioplayernode

3
推荐指数
1
解决办法
3431
查看次数

标签 统计

avaudioengine ×1

avaudioplayernode ×1

ios ×1

null ×1

swift ×1