Mp3文件在swift中不起作用,但在联机流中起作用
我的本地路径Mp3文件在swift中不起作用,但在联机流中起作用,swift,avplayerlayer,avplayeritem,Swift,Avplayerlayer,Avplayeritem,我的本地路径 file:///var/mobile/Containers/Data/Application/AF374CD7-0634-4162-A735-95EEB2878EA7/Documents/27386390cd5515bfc01a8a5573a4ae2d764268c3.mp3如果您再次询问此问题,请删除此问题。不要用重复的东西把网站弄得乱七八糟。谢谢。你能打印出url_1吗?它看起来像什么? let isMediaSongExists:Bool = Utilitie
file:///var/mobile/Containers/Data/Application/AF374CD7-0634-4162-A735-95EEB2878EA7/Documents/27386390cd5515bfc01a8a5573a4ae2d764268c3.mp3如果您再次询问此问题,请删除此问题。不要用重复的东西把网站弄得乱七八糟。谢谢。你能打印出url_1吗?它看起来像什么?
let isMediaSongExists:Bool = Utilities.isMediaExists(songInfo.songURL)
if(isMediaSongExists){
let localMediaPath = Utilities.getMediaLocalPath(songInfo.songURL)
print("File Path = \(localMediaPath)")
let url_1 = NSURL.fileURLWithPath(localMediaPath)
playerItem = AVPlayerItem(asset: AVURLAsset(URL: url_1))
}else{
playerItem = AVPlayerItem(URL:NSURL(string:url!)!)
}
// if avPlayer is not nil and if we are going to create new Object for avPlayer, we need to remove the KVO Observer.
//Otherwise app will crash.
if(self.avPlayer != nil){
self.avPlayer!.removeObserver(self, forKeyPath: "rate")
}
self.avPlayer = AVPlayer(playerItem:playerItem)
if(self.avPlayer != nil){
self.avPlayer!.addObserver(self, forKeyPath: "rate", options: .New, context:nil)
self.avPlayer!.rate = 1.0
self.avPlayer!.play()
}