I am using a UIImagePickerController with a custom overlay to record videos in my application. To implement the UIImagePickerController, I used the code from the excellent Ray Wenderlich tutorial.
I hid the controls for the camera and created a simple custom overlay view. This worked and booted normally. Then I created a toolbar and buttons for viewing to record the video:
- (BOOL) startCameraControllerFromViewController: (UIViewController*) controller usingDelegate: (id <UIImagePickerControllerDelegate, UINavigationControllerDelegate>) delegate { if (([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera] == NO) || (delegate == nil) || (controller == nil)) return NO; UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init]; cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera; // Displays a control that allows the user to choose movie capture cameraUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil]; // Hides the controls for moving & scaling pictures, or for // trimming movies. To instead show the controls, use YES. cameraUI.allowsEditing = NO; cameraUI.delegate = delegate; //Overlay view and toolbar setup // creating overlayView UIView* overlayView = [[UIView alloc] initWithFrame:cameraUI.view.frame]; // letting png transparency be float width = 320; float AR = (4.0/3.0); float toolbar_height = 480 - (AR*width); UIToolbar *toolBar=[[UIToolbar alloc]initWithFrame:CGRectMake(0, (AR*width), 320, toolbar_height)]; //toolBar.tintColor = [UIColor colorWithRed:(252/255.) green:(0/255.) blue:(48/255.) alpha:1]; toolBar.tintColor = [UIColor colorWithRed:(49/255.) green:(52/255.) blue:(49/255.) alpha:1]; UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; UIBarButtonItem *RecordBarButtonItem = [[UIBarButtonItem alloc ] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(recordPressed:)]; UIBarButtonItem *CancelBarButtonItem = [[UIBarButtonItem alloc ] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(imagePickerControllerDidCancel:)]; NSArray *buttons = [NSArray arrayWithObjects: CancelBarButtonItem, flexibleSpace, RecordBarButtonItem, flexibleSpace, nil]; [toolBar setItems: buttons animated:NO]; [overlayView addSubview:toolBar]; [overlayView.layer setOpaque:NO]; overlayView.opaque = NO; cameraUI.showsCameraControls = NO; cameraUI.cameraOverlayView = overlayView; [controller presentViewController: cameraUI animated: YES completion:nil]; return YES; }
My record button BarButtonItem calls recordPressed , which is set:
- (void) recordPressed: (UIImagePickerController *) picker { NSLog(@"lets record"); [picker startVideoCapture]; }
So the "let record" entry appears in the log, but I get an NSInvalidArgumentException for startVideoCapture. I know that something is clearly wrong with the way I try to start capturing a video with the click of a button, but I cannot figure it out. Still quite new to iOS, forgive me if the solution is simple! Hooray, Mike
source share