从YPImagePicker Swift将多个图像/视频上传到Firebase5

时间:2018-11-13 20:14:22

标签: swift firebase video image-uploading

不知道如何从YPImagePicker控制器上传图像或视频或图像和视频的组合

下面是我的PhotoSelelctorController中导入YPImagePicker的相关代码。有人曾经使用YPImagePicker将多个文件上传到Firebase吗?我正在寻找帮助...

相关代码如下: ...

@objc func handleShare() {
    if selectedItems.count > 0 {
        let gallery = YPSelectionsGalleryVC(items: selectedItems) { g, _ in
            g.dismiss(animated: true, completion: nil)
        }
        let navC = UINavigationController(rootViewController: gallery)
        self.present(navC, animated: true, completion: nil)
    } else {
        print("No items selected yet.")

    }
}

@objc
func showPicker() {

    var config = YPImagePickerConfiguration()
    config.library.mediaType = .photoAndVideo
    config.shouldSaveNewPicturesToAlbum = false
    config.video.compression = AVAssetExportPresetMediumQuality
    config.startOnScreen = .library
    config.screens = [.library, .photo, .video]
    config.video.recordingTimeLimit = 15.0
    config.video.libraryTimeLimit = 30.0
    config.showsCrop = .rectangle(ratio: (16/9))
    config.wordings.libraryTitle = "Gallery"
    config.hidesStatusBar = false
    config.hidesBottomBar = false
    config.library.maxNumberOfItems = 5
    config.library.skipSelectionsGallery = false

    let picker = YPImagePicker(configuration: config)

    picker.didFinishPicking { [unowned picker] items, cancelled in
        if cancelled {
            picker.dismiss(animated: true, completion: nil)
            return
        }
        _ = items.map { print(" \($0)") }

        self.selectedItems = items
        if let firstItem = items.first {
            switch firstItem {
            case .photo(let photo):
                self.selectedImageV.image = photo.image
                picker.dismiss(animated: true, completion: nil)
            case .video(let video):
                self.selectedImageV.image = video.thumbnail

                let assetURL = video.url
                let playerVC = AVPlayerViewController()
                let player = AVPlayer(playerItem: AVPlayerItem(url:assetURL))
                playerVC.player = player

                picker.dismiss(animated: true, completion: { [weak self] in
                    self?.present(playerVC, animated: true, completion: nil)
                    print(" \(String(describing: self?.resolutionForLocalVideo(url: assetURL)!))")
                })
            }
        }
    }
    present(picker, animated: true, completion: nil)
}

fileprivate func setupNavigationButtons() {
    navigationController?.navigationBar.tintColor = .black
    navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(handleCancel))

    navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Next", style: .plain, target: self, action: #selector(handleNext))
}

@objc func handleNext() {
  // handle submit images/videos
}

@objc func handleCancel() {
    dismiss(animated: true, completion: nil)
}

0 个答案:

没有答案