【发布时间】:2016-03-03 00:20:59
【问题描述】:
我正在处理这个记录器项目,这段代码是用 swift 2.0 编写的,它给出了这个问题! 我似乎有类似的标题帖子,但与我遇到的问题无关
导入 UIKit 导入 AVFoundation
类 PlaySoundViewController: UIViewController {
var audioPlayer: AVAudioPlayer!
var receivedAudio: AudioRecorded!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
do{
let audioPlayer = try AVAudioPlayer(contentsOfURL: receivedAudio.filePathUrl) --> ***The error happens here***
audioPlayer.enableRate = true
}catch let ErrorType {
NSLog("Could not create AVAudioPlayer: \(ErrorType)")
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func playFastSound(sender: AnyObject) {
audioPlayer.stop()
audioPlayer.play()
audioPlayer.rate = 2.0
}
@IBAction func playSlowSound(sender: AnyObject)
{
audioPlayer.stop()
audioPlayer.play()
audioPlayer.rate = 0.5
}
@IBAction func stopPlaying(sender: AnyObject) {
audioPlayer.stop()
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
【问题讨论】:
-
你能把“receivedAudio.filePathUrl”返回的网址贴出来