gpt4 book ai didi

iphone - 在 Assets 库中写入视频然后获取其属性的正确方法是什么

转载 作者:可可西里 更新时间:2023-11-01 04:36:02 24 4
gpt4 key购买 nike

我正在使用 Assets 库编写视频[库 writeVideoAtPathToSavedPhotosAlbum:movieUrl completionBlock:^(NSURL *assetURL, NSError *error) block 在视频完全写入 Assets 库之前给出 url。当我枚举 block 内的库以获取视频的属性时,我没有根据上述 block 给出的 url 获得任何视频。如果我使用相同的 url 手动重新枚举 Assets 库 3 或 4 次,我将获得视频属性。当我制作持续时间大于 5 分钟的视频时,通常会出现此问题我的代码是:

    library = [[ALAssetsLibrary alloc] init];
[library writeVideoAtPathToSavedPhotosAlbum:movieUrl completionBlock:^(NSURL *assetURL, NSError *error)
{
savedAssetURL = assetURL;
[self assetsEmumeration:assetURL];
NSLog(@"asset url %@",assetURL);
if(error)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Failed" message:[error localizedDescription] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:Nil];
[alertView show];
}
}];

-(void) assetsEmumeration:(NSURL *)_url
{
NSLog(@"assets enumeration ");
ALAssetsLibrary *al;
void (^assetGroupEnumerator)(ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop)
{
[group setAssetsFilter:[ALAssetsFilter allVideos]] ;
[group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop)
{
if (asset)
{
ALAssetRepresentation *representation = [asset defaultRepresentation];
NSURL *url = [representation url];
if([[url absoluteString] isEqualToString:[_url absoluteString]])
{
found = TRUE;
NSDictionary *asset_options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
AVAsset *avAsset = [[AVURLAsset alloc] initWithURL:url options:asset_options];
Float64 dur = CMTimeGetSeconds(avAsset.duration);
NSString *fileName = [representation filename];

appDelegate.videoLength = [NSString stringWithFormat:@"%f seconds",dur];
appDelegate.videoSize = [NSString stringWithFormat:@"%lld bytes",[representation size]];
appDelegate.originalFileName = [NSString stringWithFormat:@"%@",fileName];
[MBProgressHUD hideHUDForView:self.view animated:YES];
ExtraInfoViewController *extraInfoViewObj = [[ExtraInfoViewController alloc] init];
[self.navigationController pushViewController:extraInfoViewObj animated:YES];
NSLog(@"duration:%f,fileName:%@",dur,fileName);
}
else
{
found = FALSE;
}
}
}];
if(found == FALSE)
{
NSLog(@"video not found");
}
};
void (^assetFailureBlock)(NSError *) = ^(NSError *error)
{
NSLog(@"failure");
if(ALAssetsLibraryAccessGloballyDeniedError)
{
UIAlertView *alerview = [[UIAlertView alloc] initWithTitle:@"Denied" message:@"Failed to get the meta data. Access to assets library is denied" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:Nil];
[alerview show];
}
};
al=[RecordVideoViewController defaultAssetsLibrary];
[al enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:assetGroupEnumerator failureBlock:assetFailureBlock];
}

最佳答案

// find out alAsset for that url and then do whatever you want with alAsset. 
library = [[ALAssetsLibrary alloc] init];
[library writeVideoAtPathToSavedPhotosAlbum:movieUrl completionBlock:^(NSURL *assetURL, NSError *error)
{
savedAssetURL = assetURL;
NSLog(@"asset url %@",assetURL);
if(error)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Failed" message:[error localizedDescription] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:Nil];
[alertView show];
}
else
{
[library assetForURL:assetURL
resultBlock:^(ALAsset* alAsset) {
// do whatever you want with alAsset
}];
}
}];

关于iphone - 在 Assets 库中写入视频然后获取其属性的正确方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14124889/

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