简体   繁体   中英

UIImagePickerController video recording starts after delay or not working

I am working on a application which needs custome camera UI. SO I used Overlay view in ImagePickerController. User can switch between capture modes. ( UIImagePickerControllerCameraCaptureMode.Video and UIImagePickerControllerCameraCaptureMode.Photo )

My problem is when user swich capture mode from .Photo to .Video startVideoCapture() function is taking time (up to 5 seconds) to initialize the video capturing at firs or second time.

Sometimes it does not save video on specified path. .Photo mode is working fine. At starting I initialized imagePickerController with .Photo mode. And user could switch .Photo to .Video. I thought may be initializing .Video mode would have taken time. For this I initialize the imagePickerController with .Video mode and set a timer to change .video to .Photo mode in 4 seconds. While these 4 seconds user cannot see camera as I have added Loading screen to stop user interaction.

But still problem persist. startVideoCapture() taking time to start recording for very first time. And sometimes it does not save video on specified path after recording.

Here is my code to save video in delegate method.

/**
*  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

       }



}

This is my initializing code

    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

Somebody please help.

I found a wonderful library with all mediapickercontroller features. You should try it. IQMediaPickerController

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM