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

后端 未结 3 1359
爱一瞬间的悲伤
爱一瞬间的悲伤 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 19:51

    Try this ::

    -(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
    {
        [self dismissViewControllerAnimated:NO completion:nil];
        NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
    
        if ([type isEqualToString:(NSString *)kUTTypeVideo] || [type isEqualToString:(NSString *)kUTTypeMovie])
        {
            videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
    
            NSLog(@"found a video");
    
            // Code To give Name to video and store to DocumentDirectory //
    
            videoData = [[NSData dataWithContentsOfURL:videoURL] retain];
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString *documentsDirectory = [paths objectAtIndex:0];
    
            NSDateFormatter *dateFormat = [[[NSDateFormatter alloc] init] autorelease];
            [dateFormat setDateFormat:@"dd-MM-yyyy||HH:mm:SS"];
            NSDate *now = [[[NSDate alloc] init] autorelease];
            theDate = [dateFormat stringFromDate:now];
    
            NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"Default Album"];
    
            if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
                [[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:nil];
    
            NSString *videopath= [[[NSString alloc] initWithString:[NSString stringWithFormat:@"%@/%@.mov",documentsDirectory,theDate]] autorelease];
    
            BOOL success = [videoData writeToFile:videopath atomically:NO];
    
            NSLog(@"Successs:::: %@", success ? @"YES" : @"NO");
            NSLog(@"video path --> %@",videopath);
        }
    }
    

    Hopefully, It'll help you.

    Thanks.

提交回复
热议问题