簡體   English   中英

影片無法在AVPlayer中播放

[英]Video is not playing in AVPlayer with

我正在使用AVPlayer播放帶有localPath URL的視頻,但未在AVPlayer播放。

我正在使用以下代碼獲取localPath

var selectedAssets = [TLPHAsset]()

for abcd in self.selectedAssets {
        let asset = abcd

        if asset.type == .video {


          //------------- Video Path --------------------//
          let fm = FileManager.default
          let docsurl = try! fm.url(for:.documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
          let url = docsurl.appendingPathComponent(stringUrl!)

      }
 }

這是路徑:-

file:///var/mobile/Containers/Data/Application/915BA33E-5DB9-42C4-B5CD-3898D81FBDC5/Documents/77666c29-75a3-4d89-aecf-15d0f47fbe83.mp4

let video = dbImageDataModel[indexPath.row].fileUrl
print(video)
playerView = AVPlayer(url: URL(fileURLWithPath: video))
playerViewController.player = playerView
self.present(playerViewController, animated: true, completion: {
      self.playerViewController.player!.play()
})

您使用了錯誤的API。

absoluteString返回包含file://方案的URL字符串。 要創建新的URL,您必須使用URL(string而不是URL(fileURLWithPath

澄清

  • absoluteString返回file:///var/mobile/Containers/Data/Application... 要創建URL,請使用URL(string:
  • path返回/var/mobile/Containers/Data/Application... 要創建URL,請使用URL(fileURLWithPath:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM