我有AVUrlAsset像這樣的「file:///var/mobile/Media/DCIM/101APPLE/IMG_1006.MOV」。我如何從Swift中的這個URL訪問視頻?如何在swift 3.3x中從AVURLAsset URL訪問視頻/圖像?
1
A
回答
1
這樣,您就可以獲取所有視頻
DispatchQueue.global(qos: .background).async {
PHPhotoLibrary.requestAuthorization { (status) -> Void in
let allVidOptions = PHFetchOptions()
allVidOptions.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.video.hashValue) //Any type you want to fetch
allVidOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: true)]
//Now the set the option to `fetchAssets`
let allVids = PHAsset.fetchAssets(with: allVidOptions)
print("All Videos Count \(allVids.count)")
for index in 0..<allVids.count {
let videoRequestOptions = PHVideoRequestOptions()
videoRequestOptions.deliveryMode = .fastFormat //quality-> 360p mp4
videoRequestOptions.version = .original
PHImageManager.default().requestPlayerItem(forVideo: allVids[index], options: videoRequestOptions , resultHandler: { (playerItem, result) in
// print(result as! [String: AnyObject])
// print(playerItem)
let currentVideoUrlAsset = playerItem?.asset as? AVURLAsset
let currentVideoFilePAth = currentVideoUrlAsset!.url
let lastObject = currentVideoFilePAth.pathExtension
print(lastObject)
if lastObject == "M4V" {
self.arrOfVideos.append(playerItem!)
}
//NSString *lastPath = [videoURL lastPathComponent];
//NSString *fileExtension = [lastPath pathExtension];
//NSLog(@"File extension %@",fileExtension);
var i = Int()
print("Appending.... \(i);)")
i += 1
print("My Videos Count \(self.arrOfVideos.count)")
DispatchQueue.main.async(execute: {
self.tblVideos.reloadData()
})
})
//fetch Asset here
//print(allVids[index].description)
// print(self.arrOfVideos) //will show empty first then after above completion the execution will come here again
}
}
}
2
我想,你已經知道的URL路徑。那麼你可以做如下:
let urlStr = URL.init(fileURLWithPath:"file:///var/mobile/Media/DCIM/101APPLE/IMG_1006.MOV")
let asset = AVURLAsset.init(url: urlStr)
相關問題
- 1. AVURLAsset拒絕加載視頻
- 2. 從程序訪問圖像/音頻/視頻文件
- 3. 如何在Swift中訪問父視圖中的容器視圖子視圖
- 4. 如何在Surface視圖中訪問視頻
- 5. 在Swift中的URL圖像
- 6. 如何從視頻播放的視頻中獲取圖像?
- 7. 如何從視頻/快速視頻中保存圖像?
- 8. 如何在html中使用url顯示視頻或圖像?
- 9. 如何在Swift中訪問圖像資產(如數組)
- 10. 我如何從手機訪問攝像頭視頻?
- 11. 如何從瀏覽器URL訪問位於java服務器中的PDF /圖像/視頻文件?
- 12. 如何在圖庫視圖中顯示視頻,如圖像?
- 13. Android圖像從URL到圖像視圖
- 14. 從圖像創建視頻
- 15. 如何從Swift中的本地視頻網址獲取預覽圖像
- 16. 如何在swift中播放視頻中的視頻
- 17. 如何訪問Swift中的scrollView中的單個視圖
- 18. 圖像引擎,如何在視圖中訪問我的頁面中的圖像
- 19. 如何在Zend視圖助手中訪問url變量的值?
- 20. 從圖像生成視頻
- 21. 如何在ios swift中播放視頻
- 22. 訪問SVG中的圖像元素URL
- 23. 如何在Swift 2中使用AVPLayer從遠程URL播放視頻
- 24. 訪問bing視頻的縮略圖圖像
- 25. Swift - 從視頻中刪除音頻
- 26. 從containerView中,如何訪問包含Swift中容器的視圖控制器?
- 27. 從Xcode中的Assets.xcassets中的文件夾訪問圖像Swift
- 28. 如何在表視圖中播放recored視頻輸出url
- 29. 訪問視頻中的幀
- 30. 如何在powerapps中訪問視圖
你''AVUrlAsset? –
可以說我只是有網址(文件:///var/mobile/Media/DCIM/101APPLE/IMG_1006.MOV)多數民衆贊成它,所以我怎麼可以從中訪問媒體? iOS不允許直接訪問您通過'PHImageManager'訪問的文件路徑 – Ganesh
,您將從中獲取'playerItem'。 –