gpt4 book ai didi

swift - phasset如何获取视频url?

转载 作者:行者123 更新时间:2023-11-28 12:03:26 33 4
gpt4 key购买 nike

显示相机胶卷中的所有视频并在 UICollectionView 中显示它们。

phasset如何获取视频url?

    var videos: PHFetchResult<PHAsset>!

fileprivate func fetchVideos() {
print("fetch Videos")
let fetchOptions = PHFetchOptions()
fetchOptions.sortDescriptors = [ NSSortDescriptor(key: "creationDate", ascending: false) ]
fetchOptions.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.video.rawValue)
videos = PHAsset.fetchAssets(with: fetchOptions)
print(videos)
collectionView?.reloadData()
}

override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print(indexPath.row)

let asset = videos!.object(at: indexPath.row)
???

}

CollectionViewCellHeader;

let fileUrl = ""

override init(frame: CGRect) {
super.init(frame: frame)

let videoURL = "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"

let fileUrl = NSURL(string: videoURL) as! URL


var aPlayer = AVPlayer(url: fileUrl)
let moviePlayerController = AVPlayerViewController()

moviePlayerController.player = aPlayer
moviePlayerController.view.frame = CGRect(x:0, y:0, width:frame.size.width, height:frame.height)
moviePlayerController.videoGravity = AVLayerVideoGravity.resizeAspectFill.rawValue
moviePlayerController.view.sizeToFit()
moviePlayerController.showsPlaybackControls = false
moviePlayerController.player?.play()
addSubview(moviePlayerController.view)

}

如何获取选定的视频网址?如何使用 requestPlayerItem() 方法?

最佳答案

How do I get the selected video URL

你不知道。你不需要它。 PHImageManager 以各种形式直接从 PHAsset 给你视频,这取决于你想用它做什么。

例如,如果您的目标是播放视频,请调用此方法:

https://developer.apple.com/documentation/photos/phimagemanager/1616958-requestplayeritem

关于swift - phasset如何获取视频url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49868173/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com