简体   繁体   English

影片无法在AVPlayer中播放

[英]Video is not playing in AVPlayer with

I am using AVPlayer to play a video with the localPath URL but it is not playing on AVPlayer . 我正在使用AVPlayer播放带有localPath URL的视频,但未在AVPlayer播放。

And i am getting localPath with this code: 我正在使用以下代码获取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!)

      }
 }

here is the path:- 这是路径:-

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

You are using the wrong API. 您使用了错误的API。

absoluteString returns the URL string including the file:// scheme. absoluteString返回包含file://方案的URL字符串。 To create a new URL you have to use URL(string rather than URL(fileURLWithPath . 要创建新的URL,您必须使用URL(string而不是URL(fileURLWithPath

To clarify 澄清

  • absoluteString returns file:///var/mobile/Containers/Data/Application... . absoluteString返回file:///var/mobile/Containers/Data/Application... To create an URL use URL(string: 要创建URL,请使用URL(string:
  • path returns /var/mobile/Containers/Data/Application... . path返回/var/mobile/Containers/Data/Application... To create an URL use URL(fileURLWithPath: 要创建URL,请使用URL(fileURLWithPath:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM