在iOS中选择并上载视频

在iOS中选择并上载视频,ios,swift,uiview,Ios,Swift,Uiview,我正在构建一个应用程序,使用户能够从gallery中选择视频并将其上载到数据库 但是,我无法选择用户选择的视频并将其传递给UIView/UIImageView 例如,用户选择视频,但当按下“选择”按钮时,无法压缩视频并将其从多媒体资料传递到UIView。压缩后,它将显示此输出 下面的代码是我的按钮,允许用户“拍摄视频”或“从多媒体资料中选择” 我将使用avapturesession进行实时视频(从摄像头),并使用照片库访问多媒体资料中的视频,然后在屏幕上显示该视频,我将使用AVPlayer或AV

我正在构建一个应用程序,使用户能够从gallery中选择视频并将其上载到数据库

但是,我无法选择用户选择的视频并将其传递给UIView/UIImageView

例如,用户选择视频,但当按下“选择”按钮时,无法压缩视频并将其从多媒体资料传递到UIView。压缩后,它将显示此输出

下面的代码是我的按钮,允许用户“拍摄视频”或“从多媒体资料中选择”


我将使用
avapturesession
进行实时视频(从摄像头),并使用
照片
库访问多媒体资料中的视频,然后在屏幕上显示该视频,我将使用
AVPlayer
AVPlayerController
,然后将其发送到您正在使用的任何服务器,将视频编码为基于
的64
。。。UIImageVIew没有播放视频共享代码的能力:UIImagePickerControllerDelegate。UIImageView只显示视频的缩略图。你是什么意思@NguyenHoanare您是否使用imageView从gallery添加视频?如果是,请使用AVPlayer。imageView不支持此类内容。在选择数据之前,只需检查您拾取的数据类型,如(.video)将其添加到AVPlayer而不是uiimageView
@IBAction func videoBtn(_ sender: Any)
{
    let alert = UIAlertController(title: "Pick Image Source", message: "", preferredStyle: .alert)

    let takePhotoBtn = UIAlertAction(title: "Take Video", style: .default, handler: {(_ action: UIAlertAction) -> Void in
        let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
        let VideoViewController = storyBoard.instantiateViewController(withIdentifier: "VideoViewController") as! VideoViewController
        self.present(VideoViewController, animated:true, completion:nil)
    })

    let galleryBtn = UIAlertAction(title: "Select from Gallery", style: .default, handler: {(_ action: UIAlertAction) -> Void in
        if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.photoLibrary) {
            let imagePicker = UIImagePickerController()
            imagePicker.delegate = self
            imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary
            imagePicker.allowsEditing = true
            self.present(imagePicker, animated: true, completion: nil)
            imagePicker.mediaTypes = ["public.movie"]
        }
    })

    let cancelBtn = UIAlertAction(title: "Cancel", style: .default, handler: {(_ action: UIAlertAction) -> Void in
        // print("Cancel")
    })

    alert.addAction(takePhotoBtn)
    alert.addAction(galleryBtn)
    alert.addAction(cancelBtn)

    present(alert, animated: true, completion: { _ in })
}