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

Ios 保存我在应用程序中录制的视频,ios,video,sdk,camera,Ios,Video,Sdk,Camera,在我的学习过程中,我成功地理解了如何制作相机应用程序:-) 我唯一要做的就是保存我录制的视频。我可以保存一张照片,但这不适用于视频 因此,我想我已经几乎得到了iBrad应用程序的帮助 获取此代码: -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { NSString *mediaType = [info obj

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

我唯一要做的就是保存我录制的视频。我可以保存一张照片,但这不适用于视频

因此,我想我已经几乎得到了iBrad应用程序的帮助

获取此代码:

-(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语句,因为该应用程序可以拍摄视频和静态图像

第一部分是静止的-这很有效,然后第二部分我仍在练习:-)

试试这个:

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

听起来我的方法是正确的-我添加了一些代码来显示我在做什么-如果电影为零或如果新媒体为零,请欢呼。对不起,这是一个问题还是答案?newMedia是一个布尔值,所以我认为它应该是零,这样它就可以保存剪辑了,对吗?也许我在这里走错了路。检查这两个物体是否都存在,然后我们将从那里开始工作;布尔新媒体;它们就在我的.h文件中——它们呈绿色,所以它可以识别它们。