ios - 如何快速打开电影画廊

标签 ios swift media-player uiimagepickercontroller video-gallery

我正在尝试在 iPad 上打开电影图库,但出现此错误,而且我不知道为什么。

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Source type must be UIImagePickerControllerSourceTypeCamera'

这是我的代码:

func GaleriaVideo() {
   if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.SavedPhotosAlbum) {
        println("Galeria Video")

        imagePicker.delegate = self
        imagePicker.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum
        imagePicker.mediaTypes = [kUTTypeMovie]
        imagePicker.allowsEditing = false

        imagePicker.showsCameraControls = false

        imagePicker.modalPresentationStyle = .Custom
        self.presentViewController(self.imagePicker, animated: true, completion: nil)
    }
}

类似的代码适用于我的照片库,但我不知道为什么这不起作用。

你能告诉我我的代码有什么问题,或者我必须搜索什么才能做到这一点吗?几天前我正在尝试这个,但我感到迷失了。

谢谢你,

编辑:

这是我的照片库,它可以正常工作:

    func GaleriaImagen() {

    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.SavedPhotosAlbum){
        println("Galeria Imagen")

        imagePicker.delegate = self
        imagePicker.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum
        imagePicker.allowsEditing = false

        imagePicker.modalPresentationStyle = .Custom
            self.presentViewController(self.imagePicker, animated: true, completion: nil)

    }
}
func imagePickerControllerDidCancel(picker: UIImagePickerController!) {

    self.dismissViewControllerAnimated(false, completion: nil)
}

func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: NSDictionary!) {
    self.dismissViewControllerAnimated(true, completion: nil)
}

最佳答案

试试这个

func GaleriaVideo() {
   if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.SavedPhotosAlbum) {
        println("Galeria Video")

        imagePicker.delegate = self
        imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
        imagePicker.mediaTypes = [kUTTypeMovie]
        imagePicker.allowsEditing = false

        imagePicker.showsCameraControls = false

        imagePicker.modalPresentationStyle = .Custom
        self.presentViewController(self.imagePicker, animated: true, completion: nil)
    }
}

关于ios - 如何快速打开电影画廊,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29276298/

相关文章:

iphone - 是否有关于如何在 OpenGL ES 1.1 中使用顶点缓冲区对象 (VBO) 的最小化示例?

ios - 在拖放编辑模式下,UITableViewCell 不会超出其行

Swift:if let 语句中的条件类型转换(as?,as!)

audio - 是否有一个好的 React Native 模块用于播放/流式传输音频?

ios - UILabel 在 initWithCoder 中为 nil

ios - 如何快速遍历NSArray

ios - SwiftUI - 2 句柄范围 slider

swift - #selector 的局部函数

java - 如何循环使用 mediaplayer - Android

ios - UIImageView图像随着不同的歌曲而变化