Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 如何获取视频url?_Swift_Url_Video_Uicollectionview_Avplayer - Fatal编程技术网

Swift 如何获取视频url?

Swift 如何获取视频url?,swift,url,video,uicollectionview,avplayer,Swift,Url,Video,Uicollectionview,Avplayer,在camera roll中显示所有视频并在UICollectionView中显示它们 如何获取视频url var videos: PHFetchResult<PHAsset>! fileprivate func fetchVideos() { print("fetch Videos") let fetchOptions = PHFetchOptions() fetchOptions.sortDescriptors =

在camera roll中显示所有视频并在UICollectionView中显示它们

如何获取视频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)
                   ???

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

如何获取选定的视频URL

你没有。你不需要它。PHImageManager以各种形式直接从相位集为您提供视频,具体取决于您要对其执行的操作

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


链接指向文档。阅读文档。服从。一旦你有了AVPlayerItem,你就可以玩了。我不会为您编写代码;事实上,你甚至没有说你想对这段视频做什么。我回答了你问的问题。试试我说的,没关系。你以为你需要视频的URL。我回答说你不需要它,我告诉了你为什么。有人需要视频URL有多种原因。这是一个经典的开发者回答,告诉某人他们不需要视频URL,哈哈。但是谢谢你的回答anyways@BennyTheNerd这只是事实。照片库中没有任何传统意义上的视频“URL”。Phaset是视频在数据库中的“地址”。请尝试FoundPhaset.localIdentifier.asURL()
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)

}