Tôi có một ứng dụng mà tôi đang quay video. Nhưng khi ghi xong, tôi không thể lưu video ngay lập tức. Tôi cần phải thể hiện một thỏa thuận trước. Vì vậy, tôi cố gắng lưu URL tôi nhận được từ bộ chọn hình ảnh. Và lưu video vào thư viện sau. Tính năng này hoạt động tốt trong iOS4, nhưng không hoạt động trong iOS5. Tôi mới sử dụng iOS và Objective-C nên có thể tôi đã khai báo hoàn toàn thuộc tính có quyền giữ URL.Lưu trữ URL video đã ghi để lưu vào thư viện sau
này được một số mã:
.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 từ nhật ký khi didFinishPickingMediaWithInfo là:
temp movie path: file://localhost/private/var/mobile/Applications/8CFD1CB7-70A0-465C-B730-817ACE5A4F78/tmp/capture-T0x119660.tmp.hNFzkY/capturedvideo.MOV
Output từ đăng nhập khi d oing "saveMyVideo". URL đột nhiên biến thành điều này !! :
saving movie at: (
"0.31269",
"0.32899",
"0.63999",
"0.33001",
"0.3",
"0.6",
"0.15",
"0.05999"
)