1

ユーザーがrecordVideoボタンをクリックしてビデオを録画するために起動する必要があるトレーニングアプリがあります。iPadアプリでこれを行う方法はありますか。オーディオ録音はすでに行っています。ビデオ録画を行う必要があります。

4

3 に答える 3

1
//for video..
#import <MobileCoreServices/MobileCoreServices.h>
#import <AVFoundation/AVFoundation.h>
#import <MediaPlayer/Mediaplayer.h>

#import <CoreMedia/CoreMedia.h>



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];
    }

ドキュメントフォルダに保存し、フォトライブラリにも保存します

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);

}
于 2013-03-18T11:30:52.283 に答える
1

これを試して ::

-(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);
    }
}

うまくいけば、それはあなたを助けるでしょう。

ありがとう。

于 2013-03-18T11:09:17.713 に答える
0

やってみなよ :

-(void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info 
{
    NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
    [self dismissModalViewControllerAnimated:NO];
    NSString *moviePath = [[info objectForKey: UIImagePickerControllerMediaURL] path];
    if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)){
        UISaveVideoAtPathToSavedPhotosAlbum (moviePath,self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
                }
} 

-(void)video:(NSString*)videoPath didFinishSavingWithError:(NSError*)error contextInfo:(void*)contextInfo {
 if (error) {
        [AJNotificationView showNoticeInView:self.view type:AJNotificationTypeRed title:@"Video Saving Failed" linedBackground:AJLinedBackgroundTypeAnimated hideAfter:1.0];
    }
    else{        
        NSURL *videoURl = [NSURL fileURLWithPath:videoPath];
        AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoURl options:nil];
        AVAssetImageGenerator *generate = [[AVAssetImageGenerator alloc]  initWithAsset:asset];
        generate.appliesPreferredTrackTransform = YES;
        NSError *err = NULL;
        CMTime time = CMTimeMake(1, 60);
        CGImageRef imgRef = [generate copyCGImageAtTime:time actualTime:NULL error:&err];





  self.strUploadVideoURL = videoPath;
        [imgPhoto setImage:[[[UIImage alloc] initWithCGImage:imgRef] autorelease]];
        intWhenPushView = 2;
        btnShare.enabled = YES;
        btnFacebookShare.enabled = YES;



CGImageRelease(imgRef);
    [generate release];
    [asset release];
    }
}
于 2013-03-18T11:12:57.443 に答える