从Parse.com播放audio

我正试图播放一个audio文件,我保存在parsing。 我从保存的对象中获取来自PFFile的url。 当我运行的应用程序avplayer不产生任何audio。 我testing了avplayer是否正在玩下面的第一个代码片段,并打印出“播放”,这意味着播放器正在播放,但没有audio。 我也尝试设置avplayer的音量,并没有帮助。 不明白为什么不玩,如果有人想帮我。

audio文件url: http : //files.parsetfss.com/292b6f11-5fee-4be7-b317-16fd494dfa3d/tfss-ccc3a843-967b-4773-b92e-1cf2e8f3c1c6-testfile.wav

这个代码停止avplayer,如果它正在播放:

if (player.rate > 0) && (player.error == nil) { // player is playing println("Playing") } else { println("Not Playing") } 

AVPlayer代码:

 let objectAudio: PFObject = object as PFObject let parseAudio: PFFile = objectAudio.valueForKey("audioFileParse") as PFFile let audioPath: String = parseAudio.url let urlParse: NSURL = NSURL(fileURLWithPath: audioPath)! player = AVPlayer(URL: urlParse) println(player) //prints out <AVPlayer: 0x79e863c0> player.volume = 1.0 player.play() 

您正在使用错误的方法在这里获取NSURL,您尝试从指向远程服务器上的资源的URL创build本地文件URL。

而不是NSURL(fileURLWithPath: audioPath)你应该使用接受一个URLstring作为input的initalizer(见这里https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/ #// apple_ref / occ / instm / NSURL / initWithString 🙂

您当前的代码将指向本地文件系统上不存在的本地资源,而应该指向Parse服务器上的文件。

就像一个引用, URLWithStringfileURLWithPath 之间的区别URLURithString和NSURL的fileURLWithPath之间有什么区别?