How to record a video clip in ipad app and store it in documents folder

后端 未结 3 1350
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-15 19:42

I have training app i want that when user click recordVideo button camera should launch to record video, is there any way to do this in ipad app.I have done audio recording

3条回答
  •  有刺的猬
    2021-01-15 20:13

    //for video..
    #import 
    #import 
    #import 
    
    #import 
    
    
    
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
    
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
        {
            NSArray *mediaTypes = [NSArray arrayWithObject:(NSString*)kUTTypeMovie];
            picker.mediaTypes = mediaTypes ;
            picker.sourceType = UIImagePickerControllerSourceTypeCamera;
            picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo ;
    
            [self presentModalViewController:picker animated:NO];
    
            [picker release];
        }
        else
        {
            UIAlertView *alt=[[UIAlertView alloc]initWithTitle:@"Error" message:@" Camera Facility is not available with this Device" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
            [alt show];
            [alt release];
        }
    

    for saving into Document folder & it also save in photo Library

    NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString* documentsDirectory = [paths objectAtIndex:0];
    
    
            //for video
            NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
            NSLog(@"video url-%@",videoURL);
    
            NSData *videoData = [NSData dataWithContentsOfURL:videoURL];
    
            NSString * videoName = [NSString stringWithFormat:@"student_%d_%d.mp4",stud_id,imgVidID];
    
            videoPath = [documentsDirectory stringByAppendingPathComponent:videoName];
    
            NSLog(@"video path-%@",videoPath);
    
            [videoData writeToFile:videoPath atomically:YES];
    
            NSString *sourcePath = [[info objectForKey:@"UIImagePickerControllerMediaURL"]relativePath];
    
            UISaveVideoAtPathToSavedPhotosAlbum(sourcePath,nil,nil,nil);
    
    }
    

提交回复
热议问题