2017-02-08 5 views
1

両方の方法が同じであるため、写真をキャプチャして同じビューでビデオを記録する方法がわかりません。 私はそれを試しましたが、コードが正しいかどうかまだ明確ではありません。写真をキャプチャして同じビューでビデオを録画する

誰かがコードを見直して正しいかどうかを教えていただければ幸いです。以下は

コードです:

- (IBAction)CaptureRubbish:(id)sender { 
    UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 
    picker.delegate = self; 
    picker.allowsEditing = YES; 
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 

    [self presentViewController:picker animated:YES completion:NULL]; 
} 

- (IBAction)RecordRubbish:(id)sender { 
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { 
     UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 
     picker.delegate = self; 
     picker.allowsEditing = YES; 
     picker.sourceType = UIImagePickerControllerSourceTypeCamera; 
     picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil]; 

     [self presentViewController:picker animated:YES completion:NULL]; 
    } 
} 


- (void)videoPlayBackDidFinish:(NSNotification *)notification { 

    [[NSNotificationCenter defaultCenter]removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil]; 

    // Stop the video player and remove it from view 
    [self.videoController stop]; 
    [self.videoController.view removeFromSuperview]; 
    self.videoController = nil; 

    // Display a message 
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Video Playback" message:@"Just finished the video playback. The video is now removed." preferredStyle:UIAlertControllerStyleAlert]; 
    UIAlertAction *okayAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]; 
    [alertController addAction:okayAction]; 
    [self presentViewController:alertController animated:YES completion:nil]; 

} 
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 

    UIImage *chosenImage = info[UIImagePickerControllerEditedImage]; 
    self->ImageVIew.image = chosenImage; 

    [picker dismissViewControllerAnimated:YES completion:NULL]; 

    self.videoURL = info[UIImagePickerControllerMediaURL]; 
    [picker dismissViewControllerAnimated:YES completion:NULL]; 

    self.videoController = [[MPMoviePlayerController alloc] init]; 

    [self.videoController setContentURL:self.videoURL]; 
    [self.videoController.view setFrame:CGRectMake (0, 0, self.view.frame.size.width, 460)]; 
    [self.view addSubview:self.videoController.view]; 

    [[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(videoPlayBackDidFinish:) 
              name:MPMoviePlayerPlaybackDidFinishNotification 
              object:self.videoController]; 
    [self.videoController play]; 

} 
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { 

    [picker dismissViewControllerAnimated:YES completion:NULL]; 

} 
+0

- (無効)imagePickerController:(UIImagePickerController *)ピッカーdidFinishPickingMediaWithInfo:(NSDictionaryの*)の情報{}この方法であなたは写真用やビデオ用の書き込みのコードを持っています条件付きなら1つ入れてください –

+0

@HimanshuMoradiya if-else条件ではどうしたらいいですか? –

答えて

2
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 
    if (info[UIImagePickerControllerMediaType] == (NSString *) kUTTypeImage) { 
    // here your image capture code 
    } 
    else if(info[UIImagePickerControllerMediaType]== (NSString *)kUTTypeMovie) 
    { 
     // here your video capture code 
    } 
    [picker dismissViewControllerAnimated:YES completion:NULL]; 

} 
+0

この回答は客観的なcです –

関連する問題