How to play video with cookies content in iOS using AVPlayer in Swift?

…衆ロ難τιáo~ 提交于 2019-12-02 08:53:20

After going through so many ways finally I have got the solution which worked for me :

     func showVideo(url: String) {
      let videoURL = NSURL(string: url)
      let cookiesArray = HTTPCookieStorage.shared.cookies! //Stored Cookies of your request
      let values = HTTPCookie.requestHeaderFields(with: cookiesArray)// Returns a dictionary of header fields corresponding to a provided array of cookies.ex.["Cookie":"your cookies values"]
      let cookieArrayOptions = ["AVURLAssetHTTPHeaderFieldsKey": values]
      let assets = AVURLAsset(url: videoURL! as URL, options: cookieArrayOptions)
      let item = AVPlayerItem(asset: assets)
      videoPlayer = AVPlayer(playerItem: item)

      self.playerController.player =  self.videoPlayer 
      self.playerController.view.frame = self.view.frame
      self.present(self.playerController, animated: true, completion: nil)
      self.playerController.player?.play()
     }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!