【发布时间】:2019-07-17 06:41:59
【问题描述】:
我正在使用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()
})
【问题讨论】:
-
URL(fileURLWithPath: video)打印什么? -
@TheTiger 实际上我正在获取任何视频的本地路径并存储在本地数据库中并从中获取。打印后得到这个:
file:///var/mobile/Containers/Data/Application/915BA33E-5DB9-42C4-B5CD-3898D81FBDC5/Documents/77666c29-75a3-4d89-aecf-15d0f47fbe83.mp4 -
这是
print(video)的打印描述...我问这里打印URL(fileURLWithPath: video)是什么。打印您的网址并分享。 -
这是
print(video)结果file:///var/mobile/Containers/Data/Application/915BA33E-5DB9-42C4-B5CD-3898D81FBDC5/Documents/77666c29-75a3-4d89-aecf-15d0f47fbe83.mp4 -
@Coding 我在问当你将它传递给播放器时会打印什么 URL。所以在这里打印
playerView = AVPlayer(url: URL(fileURLWithPath: video))。分享URL(fileURLWithPath: video)而不是print(video)的打印说明。因为你的字符串已经包含file://。