存储录制的视频 URL 以便稍后保存到库中

发布于 2024-12-11 22:18:32 字数 2002 浏览 0 评论 0原文

我有一个录制视频的应用程序。但录制完成后,我无法立即保存视频。我需要先出示一份协议。所以我尝试保存从图像选择器获得的 URL。稍后将视频保存到库中。 这在 iOS4 中工作得很好,但在 iOS5 中却不行。 我是 iOS 和 Objective-C 的新手,所以我可能对应该保存 URL 的属性做了一些完全错误的声明。

这是一些代码:

.h

#import <UIKit/UIKit.h>
#import <AssetsLibrary/AssetsLibrary.h>


@interface Video_recViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate, UIActionSheetDelegate> {

NSURL *tempMoviePath;

}


@property (nonatomic, retain) NSURL *tempMoviePath;

.m

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

NSURL *moviePath = [info objectForKey:UIImagePickerControllerMediaURL]; 
[self dismissModalViewControllerAnimated: YES];
NSLog(@"path from image picker: %@", moviePath);
tempMoviePath = moviePath;
NSLog(@"temp movie path: %@", tempMoviePath);
//
[self performSelector:@selector(showAgree) withObject:nil afterDelay:0.5];

}

- (void)userAgreed {
NSLog(@"user agreed");
//NSLog(@"temp movie path: %@", tempMoviePath);
[self saveMyVideo:tempMoviePath];
//[self performSelector:@selector(showSurvey) withObject:nil afterDelay:0.5];
}

- (void)saveMyVideo:(NSURL *)videoURL {

NSLog(@"saving movie at: %@", videoURL);

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:videoURL])
{
    [library writeVideoAtPathToSavedPhotosAlbum:videoURL
                                completionBlock:^(NSURL *assetURL, NSError *error){}
     ];
} 
[library release]; 

}

didFinishPickingMediaWithInfo 时日志的输出是:

temp movie path: file://localhost/private/var/mobile/Applications/8CFD1CB7-70A0-465C-B730-817ACE5A4F78/tmp/capture-T0x119660.tmp.hNFzkY/capturedvideo.MOV

执行“saveMyVideo”时日志的输出。网址突然变成这样了!! :

saving movie at: (
"0.31269",
"0.32899",
"0.63999",
"0.33001",
"0.3",
"0.6",
"0.15",
"0.05999"
)

I have an application where I recording a video. But when the recording is finished, I can't save the video immediately. I need to show an agreement first. So I try to save the URL i get from the image picker. And save the video to the library later.
This worked fine in iOS4, but not in iOS5.
I'm new to iOS and Objective-C so I probably made some totally wrong declaration of the property that is supposed to hold the URL.

This is some of the code:

.h

#import <UIKit/UIKit.h>
#import <AssetsLibrary/AssetsLibrary.h>


@interface Video_recViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate, UIActionSheetDelegate> {

NSURL *tempMoviePath;

}


@property (nonatomic, retain) NSURL *tempMoviePath;

.m

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

NSURL *moviePath = [info objectForKey:UIImagePickerControllerMediaURL]; 
[self dismissModalViewControllerAnimated: YES];
NSLog(@"path from image picker: %@", moviePath);
tempMoviePath = moviePath;
NSLog(@"temp movie path: %@", tempMoviePath);
//
[self performSelector:@selector(showAgree) withObject:nil afterDelay:0.5];

}

- (void)userAgreed {
NSLog(@"user agreed");
//NSLog(@"temp movie path: %@", tempMoviePath);
[self saveMyVideo:tempMoviePath];
//[self performSelector:@selector(showSurvey) withObject:nil afterDelay:0.5];
}

- (void)saveMyVideo:(NSURL *)videoURL {

NSLog(@"saving movie at: %@", videoURL);

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:videoURL])
{
    [library writeVideoAtPathToSavedPhotosAlbum:videoURL
                                completionBlock:^(NSURL *assetURL, NSError *error){}
     ];
} 
[library release]; 

}

Output from log when didFinishPickingMediaWithInfo is:

temp movie path: file://localhost/private/var/mobile/Applications/8CFD1CB7-70A0-465C-B730-817ACE5A4F78/tmp/capture-T0x119660.tmp.hNFzkY/capturedvideo.MOV

Output from the log when doing "saveMyVideo". The URL has suddenly turn into this!! :

saving movie at: (
"0.31269",
"0.32899",
"0.63999",
"0.33001",
"0.3",
"0.6",
"0.15",
"0.05999"
)

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

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

发布评论

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

评论(1

走野 2024-12-18 22:18:32

(OP在问题编辑中回答。请参阅问题没有答案,但问题在评论中解决(或在聊天中扩展)

OP 写道:

错误的代码是:

tempMoviePath = moviePath;

因为我正在设置一个声明的属性,所以我必须使用 set &获取方法。应该是:

[self setTempMoviePath:moviePath];

显然 iOS 4 在这方面并没有那么难,但 iOS5 却无法处理。但无论如何,这样写是错误的。我承认我的错误。 :)

(Answered by the OP in a question edit. See Question with no answers, but issue solved in the comments (or extended in chat) )

The OP wrote:

The wrong code was:

tempMoviePath = moviePath;

Because I'm setting a declared property I must use the set & get methods. It should be:

[self setTempMoviePath:moviePath];

Apparently iOS 4 wasn't so hard on this, but iOS5 can't handle it. But, anyway, it was wrong writing like that. I admit my mistake. :)

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