(OSStatus错误2003334207)从文件播放

时间:2016-09-20 12:16:04

标签: ios swift xcode avaudioplayer swift3

我收到此错误:

  

(OSStatus错误2003334207)

在尝试从路径播放歌曲时,路径是有效的,因为我可以从目录播放mp3,但我无法在音频播放器中播放它,路径看起来像这样 -

file:///XXXX/XXXX/Library/Developer/CoreSimulator/Devices/1ECD7193-872E-4108-A565-F12BED6A69E0/data/Containers/Data/Application/85FD4AD1-54AF-4AD1-81A2-3BDA5CCE9D0A/Documents/Blessings.mp3

let vc = ViewController()
var myAudioPlayer: AVAudioPlayer = AVAudioPlayer()

var downloadName = [String]()
var songDest = [String]()
var nameMusicFile = String()
var mp3Url : URL!

override func viewDidLoad() {
    super.viewDidLoad()

    print(downloadName)
    print(songDest)
    let convert = URL(fileURLWithPath: songDest[0])
    playMusic(url: convert)
    // Uncomment the following line to preserve selection between presentations
    // self.clearsSelectionOnViewWillAppear = false

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem()
}


func playMusic(url: URL) {

    let path = url as URL!
    do {


    try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)

    try AVAudioSession.sharedInstance().setActive(true)
    try myAudioPlayer = AVAudioPlayer(contentsOf: path!)
    myAudioPlayer.volume = 1
    myAudioPlayer.play()
    } catch let err as NSError{
        print(err.localizedDescription)
    }
}

1 个答案:

答案 0 :(得分:1)

通常,当您尝试访问指定文件夹中不存在的文件或尝试解包具有nil值的变量时,会发生此错误。 PL。检查fetchedResultController是否正在返回一个对象。