我正在尝试将应用程序目录中的音频文件路径存储到Realm数据库中。问题是播放这些音频的方法不起作用:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var phraseVC = storyboard?.instantiateViewControllerWithIdentifier("PhraseVC") as PhraseVC
let phrase = phrases.objectAtIndex(UInt(indexPath.row)) as Phrases
phraseVC.audioName = phrase.phraseAudio
navigationController?.pushViewController(phraseVC, animated: true)
}
//////////////////////////////////////////////////////////////////////////////
class PhraseVC: UIViewController {
...
var audioPlayer: AVAudioPlayer?
var audioName:String = ""
@IBAction func playPhrase(sender: AnyObject) {
var audioURL: NSURL = NSURL.fileURLWithPath(audioName, isDirectory: true)!
var error: NSError?
audioPlayer?.stop()
audioPlayer = AVAudioPlayer(contentsOfURL: audioURL, error: &error)
audioPlayer?.play()
}
}
如何将音频存储在数据库中?我刚写了音频文件的名字。 可能是什么问题?