video recorder on iphone [closed]
This is the program that i make. But i doesn't run good. when i open this program on iphone it immediatly turn off. I will show my code and answer me what is the problem.
UIImagePickerController * videoRecorder = [[[UIImagePickerController alloc] init] autorelease];
videoRecorder.delegate = self;
videoRecorder.sourceType = UIImagePickerControllerSourceTypeCamera;
NSArray *sourceTypes = [UIImagePickerController availableMediaTypesForSourceType:videoRecorder.sourceType];
if (![sourceTypes containsObject:(NSString*)kUTTypeMovie] ) {
UIAlertView *alert = [[UIAler开发者_运维问答tView alloc] initWithTitle:nil
message:@"Device Not Supported for video Recording."
cancelButtonTitle:@"Yes"
otherButtonTitles:@"No",nil];
[alert show];
[alert release];
return;
}
videoRecorder.sourceType = UIImagePickerControllerSourceTypeCamera;
videoRecorder.mediaTypes = [NSArray arrayWithObject:(NSString*)kUTTypeMovie];
videoRecorder.videoQuality = UIImagePickerControllerQualityTypeLow;
videoRecorder.videoMaximumDuration = 120;
videoRecorder.delegate = self;
self.recorder_ = videoRecorder;
[videoRecorder release];
[self presentModalViewController:self.recorder_ animated:YES];
First: Use the code formatter in the future please. This hurts to look at.
Second: You're double releasing UIImagePicketController (videoRecorder) auto-release will release it after the current runloop exits, but you're also explicitly releasing it near the end of your method call here, so when iOS cleans up the auto-release pool, it will get a double release and crash.
I can't read the rest of this well due to the formatting, but that seems like your most likely bet for what's causing the crash.
You should edit your post and make the code readable.
The problem is that you autorelease videoRecorder in the first line so you don't have to call the -release. videoRecorder has a retain count of zero in the first line and a retain count of one when you assign it to self.recorder_. When you call the release, then retain count goes to zero and the autorelease pool makes the object go away before the recorder can be presented as a modal view controller. Remove that -release call and you should be fine. Also, your code sets the delegate and sourceType two times.
精彩评论