Swift:尝试从相机设备保存相机胶卷中的视频时出错

时间:2016-02-13 02:27:59

标签: ios swift camera

当我尝试将视频保存到相机胶卷时,我遇到了问题。

我的功能是:

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {

    let mediaType:String = info[UIImagePickerControllerMediaType] as! String

    print(mediaType)

    if mediaType == "public.image" {
        self.image = info[UIImagePickerControllerOriginalImage] as! UIImage

        if self.imagePicker.sourceType == UIImagePickerControllerSourceType.Camera {
            UIImageWriteToSavedPhotosAlbum(self.image, nil, nil, nil)
        }

    } else if mediaType == "public.movie" {
        if let path = info[UIImagePickerControllerMediaURL] as? NSURL {
            print(path)
            self.videoFilePath = path
            print(self.videoFilePath)

            let url = NSURL(string: self.videoFilePath.absoluteString)
            print(url)

            let urlString = String(self.videoFilePath.absoluteString)

            if self.imagePicker.sourceType == UIImagePickerControllerSourceType.Camera {
                if UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(urlString) {
                    UISaveVideoAtPathToSavedPhotosAlbum(urlString, nil, nil, nil)
                } else {
                    print("ERROR - UIVideoAtPathIsCompatibleWithSavedPhotosAlbum")
                }
            }
        } else {
            print("ERROR - CONVERT NSURL to path")
        }

    }

    self.dismissViewControllerAnimated(true, completion: nil)
}

当我选择拍摄视频时,mediaType的值=“public.movi​​e”,当我从相机胶卷中选择现有图像或从相机拍摄新照片时,=“public.image”。

当从相机拍摄新照片或从相机胶卷中选取现有图像时,此代码可正常工作。

path(和self.videoFilePath)= file:///private/var/mobile/Containers/Data/Application/43FF0C22-CB84-4966-A15A-EBAF9E7473F8/tmp/capture/capturedvideo.MOV

的值

url的值为= Optional(file:///private/var/mobile/Containers/Data/Application/43FF0C22-CB84-4966-A15A-EBAF9E7473F8/tmp/capture/capturedvideo.MOV)

urlString = file:///private/var/mobile/Containers/Data/Application/7A5C850D-AA4B-4143-BF73-77310C20E3B3/tmp/capture-T0x136e155b0.tmp.bOmits/capturedvideo.MOV

的值

控制台日志中的错误是:

2016-02-12 21:26:05.767 GayUrban[6981:2473709] Video file:///private/var/mobile/Containers/Data/Application/7A5C850D-AA4B-4143-BF73-77310C20E3B3/tmp/capture-T0x136e155b0.tmp.bOmits/capturedvideo.MOV cannot be saved to the saved photos album: 
Error Domain=NSURLErrorDomain Code=-1100 "The requested URL was not found on this server."
UserInfo={NSUnderlyingError=0x136ff1e20 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"},   NSErrorFailingURLStringKey=file:///file:/private/var/mobile/Containers/Data/Application/7A5C850D-AA4B-4143-BF73-77310C20E3B3/tmp/capture-T0x136e155b0.tmp.bOmits/capturedvideo.MOV, NSErrorFailingURLKey=file:///file:/private/var/mobile/Containers/Data/Application/7A5C850D-AA4B-4143-BF73-77310C20E3B3/tmp/capture-T0x136e155b0.tmp.bOmits/capturedvideo.MOV, 
NSURL=file:///file:/private/var/mobile/Containers/Data/Application/7A5C850D-AA4B-4143-BF73-77310C20E3B3/tmp/capture-T0x136e155b0.tmp.bOmits/capturedvideo.MOV, NSLocalizedDescription=The requested URL was not found on this server.}

0 个答案:

没有答案