[英]Random mp3 play with AVFoundation
override func viewDidAppear(animated: Bool) {
let fileLocation = NSBundle.mainBundle().pathForResource(self.navigationItem.title, ofType: "mp3", inDirectory: "Story")!
try! player = AVAudioPlayer(contentsOfURL: NSURL (string: fileLocation as String)!)
player.play()
我有一个包含4个MP3的文件夹,以及一个访问这4个MP3中的每一个的单元格列表。 为什么要为每个单元一次又一次地播放相同的MP3?
它甚至不是该文件夹中的第一个,它是最后一个!
我想您的导航项目标题是一个常量值。
这是在UITableView中吗? 如果是这样,请尝试通过UITableViewDelegate中的didselectviewatindexPath进行操作。 查找被单击的indexPath并使用它来为每个单元格播放mp3。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.