简体   繁体   中英

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()

I have a folder with 4 MP3s, and a cell list accessing each one of those 4 MP3s. Why is it playing the same MP3 again and again for each of those cells?

It is not even the first one from that folder, it is the last one!

单元格列表,带有mp3的文件夹!

我想您的导航项目标题是一个常量值。

Is this in a UITableView? If so, try doing it through the didselectviewatindexPath from UITableViewDelegate. Find the indexPath that is clicked and use that to play the mp3 for each cell.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM