iPhone:我的 Video Recorder API 代码不起作用
我正在尝试为我的 iPhone 3.0 和 iPhone 3.1.2 设备实现视频录制功能。我为此创建了一个示例应用程序,并在 UIView 中保留了一个名为“开始视频”的按钮。然后,当单击“开始视频”按钮时,我调用以下功能代码。
-(IBAction) StartVideo
{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.allowsEditing = YES;
//imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
imagePickerController.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
imagePickerController.delegate = self;
[self presentModalViewController:imagePickerController animated:YES];
[imagePickerController release];
}
更新:当我检查下面的代码片段以查找是否支持视频时,它会向我返回视频不支持警报,如下所述。我不明白这里出了什么问题?
NSArray *media = [UIImagePickerController availableMediaTypesForSourceType:
UIImagePickerControllerSourceTypeCamera];
if([media containsObject:(id)kUTTypeMovie])
{
imagePickerController.mediaTypes = [NSArray
arrayWithObjects:(id)kUTTypeMovie,nil];
[self presentModalViewController:imagePickerController animated:YES];
} else {
NSLog(@"Video not supported");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Nothing"
message:@"Video not supported"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"Ok", nil];
[alert show];
[alert release];
}
我也在 3.0 2G 和 3.1.2 3G 上测试了此代码,但当我单击“开始视频”并转到设备主屏幕时,它崩溃了。我下载了一些名为“录制视频”的第三方免费视频录制应用程序,它效果很棒,可以很好地录制视频和共享文件。 我想知道如何在iPhone 3.0、3.1.2和4.0设备上实现录制视频。 注意:我仅在 2G 和 3G 设备上进行测试。
有人可以指导我吗?
谢谢。
更新:
我使用 iPhone 3GS 设备测试了代码(函数:StartVideo),它按预期工作。我不知道为什么在 2G 和 3G 手机上显示“不支持视频”。
I am trying to implement Video recording functionality for my iPhone 3.0 and iPhone 3.1.2 device as well. I created a sample app for that and kept a button called "Start Video" in a UIView. Then i call the below function code when click Start Video button clicked.
-(IBAction) StartVideo
{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.allowsEditing = YES;
//imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
imagePickerController.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
imagePickerController.delegate = self;
[self presentModalViewController:imagePickerController animated:YES];
[imagePickerController release];
}
UPDATE: When i check the below code snippet to find video is supported or not, it returns me as Video not support alert as mentioned below. I don't understand what is wrong here?
NSArray *media = [UIImagePickerController availableMediaTypesForSourceType:
UIImagePickerControllerSourceTypeCamera];
if([media containsObject:(id)kUTTypeMovie])
{
imagePickerController.mediaTypes = [NSArray
arrayWithObjects:(id)kUTTypeMovie,nil];
[self presentModalViewController:imagePickerController animated:YES];
} else {
NSLog(@"Video not supported");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Nothing"
message:@"Video not supported"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"Ok", nil];
[alert show];
[alert release];
}
I tested this code on 3.0 2G and 3.1.2 3G as well, but it is crashing when i click on "Start Video" and going to device home screen. I downloaded some third party free video recording app called "Record Video", it works awesome, does video recording and share files very well.
I want to know how to implement recording video on iPhone 3.0, 3.1.2 and 4.0 devices.
NOTE: I am testing on 2G and 3G devices only.
Could somenone guide me?
Thank you.
UPDATED:
I tested the code (function: StartVideo) with iPhone 3GS device and it's working as expected. I don't know why does it say as "video not supported" on 2G and 3G phone's.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否设置委托来处理 UIImagePickerController 的返回?您需要设置一个实现 UIImagePickerControllerDelegate 协议的委托(可能是您从中呈现选择器的视图控制器)
are you setting a delegate to handle returns by the
UIImagePickerController
? you need to set a delegate (possibly the view controller you are presenting the picker from) that implements theUIImagePickerControllerDelegate
protocol