利用苹果自带相机进行录像的代码

这段利用苹果自带相机进行录像的代码由 CocoaChina 会员 “1056975026” 分享,对开发的应用中用到拍照、摄像功能的开发者应该有所帮助。

利用苹果自带相机进行录像的代码_第1张图片
  1. -(void) choosePhotoBySourceType: (UIImagePickerControllerCameraCaptureMode) sourceType
  2. {
  3.     m_imagePickerController = [[[UIImagePickerController alloc] init] autorelease];
  4.     m_imagePickerController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
  5.     m_imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
  6.     m_imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront;
  7.     //m_imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
  8.     
  9.     
  10.     NSArray *sourceTypes = [UIImagePickerController availableMediaTypesForSourceType:m_imagePickerController.sourceType];
  11.     if ([sourceTypes containsObject:(NSString *)kUTTypeMovie ])
  12.     {
  13.         m_imagePickerController.mediaTypes= [NSArray arrayWithObjects:(NSString *)kUTTypeMovie,(NSString *)kUTTypeImage,nil];
  14.     }    
  15.     
  16.     
  17.    // m_imagePickerController.cameraCaptureMode = sourceType;
  18.     //m_imagePickerController.mediaTypes
  19.     //imagePickerController.allowsEditing = YES;
  20.     
  21.     [self presentModalViewController: m_imagePickerController animated:YES];

  22. }

  23. -(void) takePhoto
  24. {
  25.     if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) 
  26.     {
  27.             
  28.         
  29.         [self choosePhotoBySourceType:nil];
  30.     }
  31. }


  32. // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
  33. - (void)viewDidLoad {
  34.     [super viewDidLoad];
  35.     
  36.     UIButton *takePhoto = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  37.     [takePhoto setTitle:@"录像" forState:UIControlStateNormal];
  38.     [takePhoto addTarget:self action:@selector(takePhoto) forControlEvents:UIControlEventTouchUpInside];
  39.     takePhoto.frame = CGRectMake(50,100,100,30);
  40.     [self.view addSubview:takePhoto];
  41. }

你可能感兴趣的:(利用苹果自带相机进行录像的代码)