从网址加载PHLivePhoto

时间:2018-04-28 19:41:55

标签: swift

我正在处理一个应用程序,它在视图控制器中显示实时照片。实时照片包含JPG和MOV文件。

我使用此代码显示JPG和MOV文件位于应用程序中的实时照片。

override func viewDidLoad() {
    super.viewDidLoad()

    let imgUrl = Bundle.main.url(forResource: "testImage", withExtension: "jpeg")
    let videoUrl = Bundle.main.url(forResource: "testVideo", withExtension: "mov")

    let previewImg = UIImage(named: "placeholder")
    self.makeLivePhoto(imgURL: iu, videoURL: vu, previewImg: previewImg!)

}

func makeLivePhoto(imgURL:URL,videoURL:URL,previewImg:UIImage) {

    PHLivePhoto.request(withResourceFileURLs: [imgURL,videoURL], placeholderImage: previewImg, targetSize: CGSize.zero, contentMode: PHImageContentMode.aspectFit, resultHandler: { (livePhoto,info) -> Void in

        var livePhotoView:PHLivePhotoView = PHLivePhotoView.init(frame: self.view.bounds)
        livePhotoView.livePhoto = livePhoto
        livePhotoView.contentMode = UIViewContentMode.scaleAspectFit
        self.view.addSubview(livePhotoView)
        livePhotoView.startPlayback(with:PHLivePhotoViewPlaybackStyle.hint
        )
    })

}

我想从网络服务器获取MOV和JPG文件。我该怎么做?有没有办法直接从网上获取JPG和MOV文件?

0 个答案:

没有答案