Mp3文件在swift中不起作用,但它正在使用在线流

时间:2016-02-17 10:32:05

标签: swift avplayerlayer avplayeritem

        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()
  }        

我的本​​地路径

文件:///var/mobile/Containers/Data/Application/AF374CD7-0634-4162-A735-95EEB2878EA7/Documents/27386390cd5515bfc01a8a5573a4ae2d764268c3.mp3

0 个答案:

没有答案