gpt4 book ai didi

ios - 将视频保存到文档而不是相册

转载 作者:行者123 更新时间:2023-11-28 20:14:29 25 4
gpt4 key购买 nike

目前,我的用户录制视频并将其保存到 iPad 的相册中。相反,我想将用我的应用程序录制的视频存储在我的应用程序目录中并保存。稍后我希望能够播放我在我的应用程序中录制的所有视频。这是我到目前为止所得到的:

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
[self dismissModalViewControllerAnimated:NO];
// Handle a movie capture
if (CFStringCompare ((__bridge_retained CFStringRef) mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo) {
NSString *moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(moviePath)) {
UISaveVideoAtPathToSavedPhotosAlbum(moviePath, self,
@selector(video:didFinishSavingWithError:contextInfo:), nil);
NSData *movieData = [NSData dataWithContentsOfURL:moviePath];
//confused on what to do after I have the movie data.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *tempPath = [documentsDirectory stringByAppendingFormat:@"/vid1.mp4"];

BOOL success = [movieData writeToFile:tempPath atomically:NO];

NSLog(@"%hhd",success);

}
}
}

注意:如果重要的话,我只录制视频,不录制图片。

最佳答案

#pragma mark -
#pragma mark File Names and Paths
// Creates the path if it does not exist.
- (void)ensurePathAt:(NSString *)path {
NSFileManager *fm = [NSFileManager defaultManager];
if ( [fm fileExistsAtPath:path] == false ) {
[fm createDirectoryAtPath:path
withIntermediateDirectories:YES
attributes:nil
error:NULL];
}
}
- (NSString *)documentPath {
if ( ! documentPath_ ) {
NSArray *searchPaths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
documentPath_ = [searchPaths objectAtIndex: 0];
documentPath_=[documentPath_ stringByAppendingPathComponent:@"VideoAlbum"];
[documentPath_ retain];
}
return documentPath_;
}

- (NSString *)audioPath {
if ( ! AudioPath_ ) {
AudioPath_ = [[self documentPath] stringByAppendingPathComponent:@"Demo"];
NSLog(@"%@",AudioPath_);
[AudioPath_ retain];
[self ensurePathAt:AudioPath_];
}
return AudioPath_;
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *type = [info objectForKey:UIImagePickerControllerMediaType];

if ([type isEqualToString:(NSString *)kUTTypeVideo] || [type isEqualToString:(NSString *)kUTTypeMovie])
{
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];

NSData *videoData = [NSData dataWithContentsOfURL:videoURL];
tempPath = [[self audioPath] stringByAppendingFormat:@"/%@.mp4",[NSDate date]];
BOOL success = [videoData writeToFile:tempPath atomically:NO];

NSLog(@"%hhd",success);
}
[[picker presentingViewController] dismissViewControllerAnimated:YES completion:nil];
}

关于ios - 将视频保存到文档而不是相册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18562429/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com