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

发布于 2024-12-18 11:53:56 字数 1448 浏览 0 评论 0原文

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

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

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

第一部分是静止的 - 有效,然后第二部分我仍然在跳舞:-)

I am succeeding in understanding how to make a camera app in my learning journey:-)

The only thing I am stuck with is saving a video that I have recorded. I am able to save a photo, but the same does not work for videos.

So I think I have almost got it with the help of iBrad Apps.

got this code:

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

I have an if statement because the app can take both video and still images.

The first part is for still - which works and then the second part I am still tutu-ing with:-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暮倦 2024-12-25 11:53:56

试试这个:

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

Try this:

UISaveVideoAtPathToSavedPhotosAlbum(moviepath,nil,nil,nil);

Edit: Try this and modify your code to this method:

// 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];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文