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
)
我正在开发一个需要自定义相机UI的应用程序。所以我在ImagePickerController中使用了Overlay视图。用户可以在捕获模式之间切换。 (UIImagePickerControllerCameraCaptureMode.Video和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.
我的问题是从.Photo到.Video startVideoCapture()函数的用户swich捕获模式需要花费时间(最多5秒)来初始化第一次或第二次的视频捕获。
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.
有时它不会在指定的路径上保存视频..照片模式工作正常。在开始时,我使用.Photo模式初始化了imagePickerController。用户可以将.Photo切换为.Video。我想可能正在初始化。视频模式需要时间。为此,我使用.Video模式初始化imagePickerController,并设置一个计时器,在4秒内将.video更改为.Photo模式。虽然这4秒钟用户无法看到相机,因为我已添加加载屏幕以停止用户交互。
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.
但问题仍然存在。 startVideoCapture()花时间开始第一次录制。有时它在录制后不会在指定的路径上保存视频。
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.
有人请帮忙。
1 个解决方案
#1
0
I found a wonderful library with all mediapickercontroller features. You should try it. IQMediaPickerController
我发现了一个包含所有mediapickercontroller功能的精彩库。你应该试试。 IQMediaPickerController
#1
0
I found a wonderful library with all mediapickercontroller features. You should try it. IQMediaPickerController
我发现了一个包含所有mediapickercontroller功能的精彩库。你应该试试。 IQMediaPickerController