简体   繁体   English

解析来自iOS Swift 2的流音频

[英]streaming audio from parse for ios swift 2

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. 编译完一切似乎还不错之后,我有一个代码可以在ios上快速解析来自ios的流音频,并且音频文件可以准确同步,但是当我选择它们时,扬声器没有音频输出。 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: 在swift 2上不再编译它的说法,即使用url的模棱两可,这是swift编写的func,希望我们可以将其转换为swift 2,谢谢:

    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? 我尚未对此进行测试(我目前没有任何解析中的音频文件),但是,为什么不访问pffile然后转换为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()
            }
        })
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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