如何让播放按钮从解析中播放某首歌曲?

时间:2015-08-23 22:44:33

标签: ios swift

我目前有一首当前正在播放的歌曲的标题,并且在解析数据库中有相同的歌曲,但是当我点击我的应用程序上的播放按钮时,它会在数据库中播放一首随机歌曲,而不是歌曲的标题。如何让播放按钮在数据库中播放某首歌?

func play(sender: UIButton!){
    //assign each button to play the certain song pertaining to the UILabel
   playing song

    println(self.NameArray)
    println("Song:  + \(Title)")
    println("Artist:  + \(Artist)")
    println("Album:  + \(Album)")


            for dbTitle in self.NameArray{

        if(dbTitle == Title){
            var SongQuery = PFQuery(className: "Songs")
            SongQuery.getObjectInBackgroundWithId(iDArray[SelectedSongNumber], block:{
                (object: PFObject?, error: NSError?) -> Void in

                if let AudioFileURLTemp = object?.objectForKey("SongFile")?.url{
                    AudioPlayer = AVPlayer(URL: NSURL(string: AudioFileURLTemp!))
                    AudioPlayer.play()//currently plays random song
                    println("playing song")
                }
            })

            println("Song in db")

        }else{
            println("Song not in db")
        }

    }


}



 var ObjectIDQuery = PFQuery(className: "Songs")
    ObjectIDQuery.findObjectsInBackgroundWithBlock({
        (objectsArray: [AnyObject]?, error: NSError?) -> Void in

        var objectIDs = objectsArray as! [PFObject]

            for i in 0...objectIDs.count-1{
            self.iDArray.append(objectIDs[i].valueForKey("objectId") as! String)
            self.NameArray.append(objectIDs[i].valueForKey("SongName") as! String)

                }

    })

0 个答案:

没有答案