简体   繁体   中英

Overlay on iPhone camera

I want to make an overlay on camera of my iphone app.I have followed this tutorial

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. You can call

– startVideoCapture
– stopVideoCapture

to record video. Check the API

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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