我正在使用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()
})
答案 0 :(得分:0)
您使用了错误的API。
absoluteString
返回包含file://
方案的URL字符串。要创建新的URL,您必须使用URL(string
而不是URL(fileURLWithPath
。
要澄清
absoluteString
返回file:///var/mobile/Containers/Data/Application...
。要创建网址,请使用URL(string:
path
返回/var/mobile/Containers/Data/Application...
。要创建网址,请使用URL(fileURLWithPath: