简体   繁体   English

在iPhone相机上覆盖

[英]Overlay on iPhone camera

I want to make an overlay on camera of my iphone app.I have followed this tutorial 我要让我的iPhone app.I的摄像头覆盖遵循教程

But it teaches about capturing the image,I need to implement it on recording the video. 但是它教如何捕获图像,我需要在录制视频时实现它。

In the tutorial it is simply 在本教程中,它只是

 - (void)takePicture
   {
    [picker takePicture];
   }

But I am not able to implement it on recording the video,Please help me with an example if you can 但是我无法在录制视频时实现它,如果可以,请帮我举个例子

Now without overlay I am using this coding for recording the video[I wish to implement it with the above tutorial] 现在没有覆盖层,我正在使用此编码来录制视频[我希望通过以上教程来实现]

 -(void)ViewDidLoad
    {

     [[NSNotificationCenter defaultCenter] addObserver:self   selector:@selector(onUploadVideoProgress:) name:@"UPLOADPROGRESS"  object:nil];

       self.mediaTypes=[NSArray arrayWithObjects:(NSString *) kUTTypeMovie,nil];


        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {
        videoRecorder = [[UIImagePickerController alloc] init];
        videoRecorder.sourceType = UIImagePickerControllerSourceTypeCamera;
        videoRecorder.delegate = self;
         NSArray *mediaTypes1 = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
        NSArray *videoMediaTypesOnly = [mediaTypes1 filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(SELF contains %@)", @"movie"]];

         if ([videoMediaTypesOnly count] == 0)       
        {
            UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Sorry but your device does not support video recording"
                                                                     delegate:nil
                                                            cancelButtonTitle:@"OK"


                                      destructiveButtonTitle:nil
                                                            otherButtonTitles:nil];
            [actionSheet showInView:[[self view] window]];
          }
         else
         {
             if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear])

            videoRecorder.cameraDevice = UIImagePickerControllerCameraDeviceRear;
            videoRecorder.mediaTypes = videoMediaTypesOnly;
            videoRecorder.videoQuality = UIImagePickerControllerQualityType640x480;
            videoRecorder.videoMaximumDuration = 30.0f;
            appDelegate.videoOrientation = @"portrait";



            [self presentModalViewController:videoRecorder animated:YES];
           }


          }
          else
          {
        UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Sorry but your   device does not support video recording"
                                                                 delegate:nil
                                                        cancelButtonTitle:@"OK"
                                                   destructiveButtonTitle:nil
                                                        otherButtonTitles:nil];
                [actionSheet showInView:[[self view] window]];
                }

             }


          }

           - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
           {
          self.videoURL=[[info objectForKey:UIImagePickerControllerMediaURL] path];
          self.videoData=[NSData dataWithContentsOfURL:[info objectForKey:UIImagePickerControllerMediaURL]];


           [self dismissModalViewControllerAnimated:YES];

       NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
     if ([mediaType compare:(NSString*)kUTTypeMovie] == NSOrderedSame) {
        NSURL *mediaUrl = [info objectForKey:UIImagePickerControllerMediaURL];
        MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:mediaUrl];
        moviePlayer.shouldAutoplay=NO;

        UIImage *thumbnail = [moviePlayer thumbnailImageAtTime:0.0 timeOption:MPMovieTimeOptionNearestKeyFrame];

        appDelegate.selectedVideo=[NSDictionary dictionaryWithObjectsAndKeys:
                                   self.videoURL,@"videourl",
                                   self.videoData,@"videodata",
                                   thumbnail,@"thumbdata",
                                   nil ];
           }

         AddOrEditVideoDetails *controller = [[AddOrEditVideoDetails alloc]initWithNibName:@"AddOrEditVideoView"bundle:nil];
    [[self navigationController] pushViewController:controller animated:YES];

        }

UIImagePickerController already has API for recording video. UIImagePickerController已经具有用于录制视频的API。 You can call 你可以打电话

– startVideoCapture
– stopVideoCapture

to record video. 录制视频。 Check the API 检查API

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM