I have a code to stream audio from parse on ios build in swift after compiling everything seems OK and the audio files sync accurately but when i select them there is no audio coming out of the speakers. on swift 2 its not compiling anymore its saying ambiguous use of url, here is the func written in swift ,i hope we can convert it to swift 2 thank you:
func grabSong(){
let 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()
}
})
}
Yeah it's working, Only you need to check the optionality, like this:
func grabSong() {
let SonQuery = PFQuery(className: "Songs")
SonQuery.getObjectInBackgroundWithId(idArray[SelectedSongNumber], block: {
(object: PFObject?, error:NSError?) -> Void in
if let audioFIleTemp: PFFile = object?.valueForKey("SongFile") as? PFFile {
AudioPlayer = AVPlayer(URL: NSURL(string: audioFIleTemp.url!)!)
AudioPlayer.play()
}
})
}
I haven't tested this (I don't have any audio files on parse currently), however, why not just access the pffile and then convert to a url? It would look something like this:
func grabSong(){
let SongQuery = PFQuery(className: "songs")
SongQuery.getObjectInBackgroundWithId(iDArray[SelectedSongNumber], block:{
(object: PFObject?, error:NSError?)-> Void in
if let songFile: PFFile = object?.valueForKey("songFile") as? PFFile {
AudioPlayer = AVPlayer(URL: songFile.url)
AudioPlayer.play()
}
})
}
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.