I have implemented the code to do video recording feature. It works fine on 3GS device. I want to restrict the video recording based on some timer setting. Lets say, i want to allow user to do video recording only upto 20 seconds or 35 seconds like that. How can i do that? Can i show the timer kind of control on top of media player while recording the video?
Please suggest me.
Here is my code for video recording:
UIImagePickerController *pickerController =
[[[UIImagePickerController alloc] init] autorelease];
pickerController.delegate = self;
pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
pickerController.showsCameraControls = YES;
pickerController.mediaTypes = [NSArray arrayWithObject:(id)kUTTypeMovie];
[self presentModalViewController:pickerController animated:YES];
videoMaximumDuration expects an NSTimeInterval, which is a tpyedef for a float value. So you should pass it a float value. Try it like this:
UIImagePickerController *pickerController = [[UIImagePickerController alloc] init];
pickerController.delegate = self;
pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
pickerController.showsCameraControls = YES;
pickerController.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie]; // kUTTypeMovie is actually an NSString.
pickerController.videoMaximumDuration = 30.0f; // limits video length to 30 seconds.
[self presentModalViewController:pickerController animated:YES];
[pickerController release];
UIImagePickerController class has property videoMaximumDuration which works for NSTimeInterval.
By default it's value is set for 10 minutes but you can change it's float value according to your need.
So if you make object of UIImagePickerController class named videoPickerController then you can set timer for capturing video like-
videoPickerController.videoMaximumDuration = 25.0f;
Related
I tried this twice with two different apps and I get the same thing. I have a set up a UIImagePIckerController instance as follows:
- (IBAction)addImage:(UIBarButtonItem *)sender {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
NSArray *mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
if ([mediaTypes containsObject:(NSString *)kUTTypeImage]) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];
picker.allowsEditing = NO;
picker.showsCameraControls = NO;
[self presentViewController: picker animated:YES completion:NULL];
}
[..]
}
This was the second. In the first I set up a custom overlay to run the shutter and other functions. Everything runs fine but I keep getting an error on the console:
<Error>: CGAffineTransformInvert: singular matrix.
When I run the app, every time I rotate (or move about which signals a rotate) the device while the camera is up {something happens here}. I tried it on both my iPhone 4 and iPad Mini with the same results. After a lot of digging I found this only happen in the case where
picker.showsCameraControls = NO;
If I put
picker.showsCameraControls = YES;
Then I get no message (though my custom overlay is hidden too). Making sure it wasn't the custom overlay itself I tried leaving that out, and it still gives the error message.
Anybody got any ideas of what I should do about this?
I believe it to be largely benign as Apple's own PhotoPicker sample code generates this warning. Rotation has to do with matrices and while I'm not sure which matrix in particular is getting rotated, it is considered a mathematical violation to perform operations on matrices with a determinant of zero (similar to dividing by zero). Such a matrix is not invertible or 'singular':
http://en.wikipedia.org/wiki/Rotation_matrix
http://en.wikipedia.org/wiki/Determinant
http://en.wikipedia.org/wiki/Singular_matrix#singular
is there any way to check video camera capability available on iPhone?
Most of the camera related availability support is exposed through the UIImagePickerController. A bit tricker thing is detection of Video Camera. You can detect the presence of a video camera in a iOS device using the following method.
- (BOOL) isVideoCameraAvailable
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
NSArray *sourceTypes = [UIImagePickerController availableMediaTypesForSourceType:picker.sourceType];
[picker release];
if (![sourceTypes containsObject:(NSString *)kUTTypeMovie ]){
return NO;
}
return YES;
}
Found this code (based on UIDevice) which helped me with this issue:
https://github.com/MugunthKumar/DeviceHelper
I am facing a strange issue with videoMaximumDuration property in Video recorder API. I am trying to fix this issue more than a week, but couldn't. I posted in several forums, but no help yet.
I am using the following code to launch Camera from my application and start recording the video. As per my requirement, i should set the time duration for recording the video to stop. So, i use "videoMaximumDuration" property to set the time duration for recording the video.
if ([types containsObject:(id)kUTTypeMovie])
{
appDelegate.pickerController = [[UIImagePickerController alloc] init];
appDelegate.pickerController.delegate = self;
appDelegate.pickerController.videoQuality = setVideoQuality;
appDelegate.pickerController.allowsEditing = NO;
appDelegate.pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
appDelegate.pickerController.showsCameraControls = YES;
appDelegate.pickerController.navigationBarHidden = YES;
appDelegate.pickerController.toolbarHidden = YES;
appDelegate.pickerController.wantsFullScreenLayout = YES;
appDelegate.pickerController.cameraViewTransform =
CGAffineTransformScale(appDelegate.pickerController.cameraViewTransform,
CAMERA_TRANSFORM_X,
CAMERA_TRANSFORM_Y);
appDelegate.pickerController.mediaTypes = [NSArray arrayWithObject:(id)kUTTypeMovie];
appDelegate.pickerController.videoMaximumDuration = maxDuration;
[self presentModalViewController:appDelegate.pickerController animated:YES];
}
Here is the issue:
If if i set videoQuality as UIImagePickerControllerQualityTypeHigh, then the time duration(videoMaximumDuration) works as expected, i.e exactly after the time duration it stops recording the video automatically. If i go and see that recorded video in Photo album to make sure that, it is recorded well as per the time.
If i change the videoQuality to UIImagePickerControllerQualityTypeMedium (or) UIImagePickerControllerQualityTypeLow like that, then the time duration(videoMaximumDuration) for video recording is not working as expected,
i.e. it is able to automatically stop the video recording at the time duration set, no issues, But if i go and see that recorded video in Photo album to make sure, it is NOT as per the time taken, rather i can see the smaller video than what i recorded. For example, if i set the videoMaximumDuration for 30 seconds, after recording the video, if i go and see that recorded video in Photo album, it could able to record= only unto 22 seconds. Seems to be issue with the API itself. This is not happening when i use video quality as UIImagePickerControllerQualityTypeHigh.
I tried even using Custom overlay view and do start and stop recording video through code like below by setting timer(NStimer). But still i see the same issue has observed.
overlay = [[OverlayView alloc]initWithFrame:CGRectMake(0, 0, 768, 1024)];
if ([types containsObject:(id)kUTTypeMovie])
{
appDelegate.pickerController = [[UIImagePickerController alloc] init];
appDelegate.pickerController.delegate = self;
appDelegate.pickerController.videoQuality = setVideoQuality;
appDelegate.pickerController.allowsEditing = NO;
appDelegate.pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
appDelegate.pickerController.showsCameraControls = NO;
appDelegate.pickerController.navigationBarHidden = YES;
appDelegate.pickerController.toolbarHidden = YES;
appDelegate.pickerController.wantsFullScreenLayout = YES;
appDelegate.mTimerSelectionForVideo = maxDuration; // TIME SET HERE IN VARIABLE
appDelegate.pickerController.cameraViewTransform =
CGAffineTransformScale(appDelegate.pickerController.cameraViewTransform,
CAMERA_TRANSFORM_X,
CAMERA_TRANSFORM_Y);
appDelegate.pickerController.mediaTypes = [NSArray arrayWithObject:(id)kUTTypeMovie];
appDelegate.pickerController.videoMaximumDuration = maxDuration;
[self presentModalViewController:appDelegate.pickerController animated:YES];
appDelegate.pickerController.cameraOverlayView =overlay;
}
OverlayView.m
-(void)startAction:(id)sender
{
BOOL bStop = TRUE;
void (^hideControls)(void);
hideControls = ^(void) {
cameraSelectionButton.alpha = 0;
startButton.enabled = NO;
lbl.hidden = NO;
};
void (^recordMovie)(BOOL finished);
recordMovie = ^(BOOL finished) {
stopButton.enabled = YES;
[appDelegate.pickerController startVideoCapture];
};
// Hide controls
[UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:hideControls completion:recordMovie];
if ( appDelegate.mTimerSelectionForVideo==0 )
{
bStop = FALSE;
}
if ( bStop )
timer = [NSTimer scheduledTimerWithTimeInterval:(appDelegate.mTimerSelectionForVideo)+1
target:self selector:#selector(stopCamera:) userInfo:nil repeats:NO];
}
- (void)stopCamera:(NSTimer *)theTimer
{
startButton.enabled = YES;
if ( timer )
{
[timer invalidate];
timer = nil;
}
[appDelegate.pickerController stopVideoCapture];
[appDelegate.pickerController dismissModalViewControllerAnimated:YES];
}
But still i see the same issue observed. Why does other video quality settings not working as per the videoMaximumDuration set?
I tested on iPhone 4.1 and iPad 4.3, the same issue has been observed. Looks like, issue with the API or video recorder hardware itself to support it.
Could someone please guild me to fix this issue if there is any possibility (or) through your experience?
Thank you in Advance!
Fixed it by creating an overlay view on top of the camera view and handle start/stop thru code.
Can I programmatically turn on the camera flash on a new iPhone 4 device, before taking a picture with -takePicture?
I'm developing a photo taking app for iOS 4 and want to power on the flash light before the user takes a picture, so they can see the effect of the flash in advance.
The problem seems to be that for the flash light to stay on, you'll need to set the torchMode on and this is only possible in 'video mode' (UIImagePickerControllerCameraCaptureModeVideo), while you can only ask the UIImagePickerController to takePicture when it is on 'photo mode' (UIImagePickerControllerCameraCaptureModePhoto).
So, the following works, but only shows the flash light when taking a picture:
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls = NO;
picker.navigationBarHidden = YES;
picker.toolbarHidden = YES;
picker.mediaTypes = [NSArray arrayWithObjects:#"public.image", nil];
picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
picker.cameraFlashMode = UIImagePickerControllerCameraFlashModeOn;
[self presentModalViewController:picker animated:YES];
And this also works (shows the torch the whole time), but then I cannot take a picture.
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls = NO;
picker.navigationBarHidden = YES;
picker.toolbarHidden = YES;
picker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie, nil];
picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
picker.cameraFlashMode = UIImagePickerControllerCameraFlashModeOn;
[self presentModalViewController:picker animated:YES];
When I try the toggleTorch code found here: Turn on torch/flash on iPhone there seems to not be any live video feed in the UIImagePickerController.
Are these UIImagePickerController and AVCaptureSession compatible with each other? or are you supposed to choose for either one or the other?
And does anybody know a workaround to get both the flash mode on (or torchMode) and to be able to takePicture?
Have a look at the WWDC 2010 sessions (specifically 409) where they go into functionality like the one you're looking for.
Essentially you need to move away from UIImagePickerController if you're looking to perform these custom camera functions and move towards AVFoundation classes.
HI,
I need to record video using iPhone. To do that i used UIImagePickerController. I have an iPhone 3G, with me. when i run my code to check if source type available it says device not supported. My OS is 3.2.1, where i am wrong, can some one tell me what i need to change.
Also is there some other way to record video. What i need to do is to get the video stream as it is recorded.
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
NSArray *sourceTypes =
[UIImagePickerController availableMediaTypesForSourceType:picker.sourceType];
if (![sourceTypes containsObject:(NSString *)kUTTypeVideo ]){
NSLog(#"device not supported");
return;
}
//picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeVideo];
picker.videoQuality = UIImagePickerControllerQualityTypeHigh;
[self presentModalViewController:picker animated:YES];
Thanks,
That is because the 3G isn't supported for video recording.
Lance is correct. The native UIImagePickerController does not work on iPhone 3G. If an app does do video recording on a 3G they are doing a hack like taking multiple photos in succession and manually encoding a video file using the individual images.