UIImagePickerController视频录制在延迟或不工作后开始

时间:2015-09-25 06:06:19

标签: ios swift camera uiimagepickercontroller video-recording

我正在开发一个需要自定义相机UI的应用程序。所以我在ImagePickerController中使用了Overlay视图。用户可以在捕获模式之间切换。 (UIImagePickerControllerCameraCaptureMode.VideoUIImagePickerControllerCameraCaptureMode.Photo

我的问题是,从.Photo.Video startVideoCapture()功能的用户swich捕获模式需要花费时间(最多5秒)来初始化第一次或第二次的视频捕获。 / p>

有时它不会在指定路径上保存视频。.Photo模式工作正常。 在开始时,我使用.Photo模式初始化了imagePickerController。用户可以将.Photo切换为.Video。我想可能正在初始化。视频模式需要时间。为此,我使用.Video模式初始化imagePickerController,并设置一个计时器,在4秒内将.video更改为.Photo模式。虽然这4秒钟用户无法看到相机,因为我已添加加载屏幕以停止用户交互。

但问题仍然存在。 startVideoCapture()花时间开始录制第一次。有时它在录制后不会在指定的路径上保存视频。

以下是我在代理方法中保存视频的代码。

/**
*  Delegate method for media capture and save media
*/
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info:[NSObject : AnyObject]) {

    overlayView.bringSubviewToFront(preView)

    let mediaType = info[UIImagePickerControllerMediaType] as! NSString

    if mediaType.isEqualToString(kUTTypeMovie as NSString as String){
        let tempMedia = info[UIImagePickerControllerMediaURL] as! NSURL!
        let pathString = tempMedia.relativePath

        if pathString != nil {

            destinationPathForVideo = "\(UtilityManager.sharedInstance.kcache)/challengeRecordings/\(NSDate()).mp4"

            NSFileManager.defaultManager().createDirectoryAtPath(destinationPathForVideo.stringByDeletingLastPathComponent, withIntermediateDirectories: true, attributes: nil, error: nil)

            UtilityManager.sharedInstance.copyFileFromSourceTo( pathString, destinationPath: destinationPathForVideo )

            // Save Image


            imageCaptured = getThumbnailForVideoPath(pathString!)
            destinationPathForImage = "\(UtilityManager.sharedInstance.kcache)/challengeRecordings/\(NSDate()).png"
            let success = UIImagePNGRepresentation(imageCaptured).writeToFile( destinationPathForImage , atomically: true)

            Log(message:"Saved: \(success)")

            imageButton!.setImage(imageCaptured, forState: .Normal)
            imageView.image = imageCaptured

       }



}

这是我的初始化代码

    imagePicker            = UIImagePickerController()
    imagePicker.delegate   = self
    imagePicker.sourceType = .Camera
    imagePicker.showsCameraControls = false
    self.imagePicker.mediaTypes = [kUTTypeMovie, kUTTypeImage]
    self.imagePicker.videoMaximumDuration = 11
    self.imagePicker.videoQuality = UIImagePickerControllerQualityType.TypeMedium
    self.imagePicker.cameraFlashMode = .Off
    self.imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Video

有人请帮忙。

1 个答案:

答案 0 :(得分:0)

我找到了一个包含所有mediapickercontroller功能的精彩图书馆。你应该试试看。 IQMediaPickerController