保存我在应用中录制的视频

时间:2011-11-29 00:08:06

标签: ios video sdk camera

我成功地了解了如何在我的学习历程中制作相机应用程序: - )

我唯一坚持的是保存我录制的视频。我可以保存照片,但同样不适用于视频。

所以我想我在iBrad Apps的帮助下几乎得到了它。

得到了这段代码:

-(void)imagePickerController:(UIImagePickerController *)picker
   didFinishPickingMediaWithInfo:(NSDictionary *)info
 {
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];

[self dismissModalViewControllerAnimated:YES];

if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
    UIImage *image = [info 
                      objectForKey:UIImagePickerControllerOriginalImage];

    imageView.image = image;

    if (newMedia)
        UIImageWriteToSavedPhotosAlbum(image, 
                                       self,
                                       @selector(image:finishedSavingWithError:contextInfo:),
                                       nil);
}
else{

    if ([mediaType isEqualToString:(NSString *)kUTTypeMovie]) {
        UIImage *movie = [info 
                          objectForKey:UIImagePickerControllerQualityTypeHigh];

        videoRecorder2.image = movie;

            if (newMedia)
                UISaveVideoAtPathToSavedPhotosAlbum(movie, 
                                               self,
                                               @selector(movie:finishedSavingWithError:contextInfo:),
                                               nil);
}}}

我有一个if语句,因为该应用可以同时拍摄视频和静止图像。

第一部分是针对静止的 - 哪部分是有效的,然后是第二部分,我仍在使用: - )

1 个答案:

答案 0 :(得分:18)

试试这个:

UISaveVideoAtPathToSavedPhotosAlbum(moviepath,nil,nil,nil);

编辑:尝试此操作并将代码修改为此方法:

// For responding to the user tapping Cancel.
- (void) imagePickerControllerDidCancel: (UIImagePickerController *) picker {

    [[picker parentViewController] dismissModalViewControllerAnimated: YES];
    [picker release];
}

// For responding to the user accepting a newly-captured picture or movie
- (void) imagePickerController: (UIImagePickerController *) picker
            didFinishPickingMediaWithInfo: (NSDictionary *) info {

    NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
    UIImage *originalImage, *editedImage, *imageToSave;

    // Handle a still image capture
    if (CFStringCompare ((CFStringRef) mediaType, kUTTypeImage, 0)
            == kCFCompareEqualTo) {

        editedImage = (UIImage *) [info objectForKey:
                    UIImagePickerControllerEditedImage];
        originalImage = (UIImage *) [info objectForKey:
                    UIImagePickerControllerOriginalImage];

        if (editedImage) {
            imageToSave = editedImage;
        } else {
            imageToSave = originalImage;
        }

    // Save the new image (original or edited) to the Camera Roll
        UIImageWriteToSavedPhotosAlbum (imageToSave, nil, nil , nil);
    }

    // Handle a movie capture
    if (CFStringCompare ((CFStringRef) mediaType, kUTTypeMovie, 0)
            == kCFCompareEqualTo) {

        NSString *moviePath = [[info objectForKey:
                    UIImagePickerControllerMediaURL] path];

        if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
            UISaveVideoAtPathToSavedPhotosAlbum (
                    moviePath, nil, nil, nil);
        }
    }

    [[picker parentViewController] dismissModalViewControllerAnimated: YES];
    [picker release];
}