这是我到目前为止所做的:
let query = PFQuery(className: "Genres")
//Find objects in the background
query.findObjectsInBackgroundWithBlock({
//store objects in an array
(objectsArray :[PFObject]?, error: NSError?) -> Void in
let objectIDs = objectsArray
// objects being added to array
for i in 0...objectIDs!.count-1{
// add a new element in the array
self.iDArray.append(objectIDs![i].valueForKey("objectId") as! String)
//store song name in song array
self.NameArray.append(objectIDs![i].valueForKey("SongName")as! String)
self.tableView.reloadData()
NSLog("\(objectIDs)")
}
})
}
func grabSong () {
let songQuery = PFQuery(className: "Genres")
songQuery.getObjectInBackgroundWithId(iDArray[SelectedSongNumber], block: {
(object: PFObject?, error : NSError?) -> Void in
if let audioFile = object?["SongFile"] as? PFFile {
let audioFileUrlString: String = (audioFile.url)!
let audioFileUrl = NSURL(string: audioFileUrlString)!
AudioPlayer = AVPlayer(URL: audioFileUrl)
AudioPlayer.play()
}
})
}
答案 0 :(得分:0)
一种可能的方法(基于您的代码)
iDArray
(如何对数组进行洗牌很容易用Google搜索。)SelectedSongNumber
设置为0 grabSong
时,请将SelectedSongNumber
增加1 SelectedSongNumber
< iDArray.count
继续加载歌曲,否则您已完成grabSong
(如何在SO上观察播放器)应该改变你喜欢的一切:)