I obtain the URL of an AVURLAsset like this:
我获取了AVURLAsset的URL,如下所示:
NSURL *url = [[asset defaultRepresentation] url];
In console, the AVURLAsset's url looks like this:
在控制台中,AVURLAsset的URL如下所示:
assets-library://asset/asset.mov?id=A3210417-4BAC-1C78-BD93-4BDD286247D9&ext=mov
I tried getting file name with extension from URL like this:
我尝试从URL获取带扩展名的文件名,如下所示:
NSString *last = [[url URLByDeletingPathExtension] lastPathComponent];
NSString *tnFileName = [NSString stringWithFormat:@"%@_tn.%@", last, url.pathExtension];
Here is console log of tnFileName:
这是tnFileName的控制台日志:
tnFileName = asset_tn.mov
tnFileName = asset_tn.mov
How can I get a string of the A3210417-4BAC-1C78-BD93-4BDD286247D9 portion? Or is there a different unique ID for an asset to use for caching still images of the asset?
如何获得A3210417-4BAC-1C78-BD93-4BDD286247D9部分的字符串?或者资产是否有不同的唯一ID用于缓存资产的静态图像?
To clarify, I need this to store thumbnails to disk and I want to use a name that matches the asset.
为了澄清,我需要将缩略图存储到磁盘,我想使用与资产匹配的名称。
2 个解决方案
#1
3
play with the string like this:
玩这样的字符串:
NSString * urlName = @"assets-library://asset/asset.mov?id=A3210417-4BAC-1C78-BD93-
4BDD286247D9&ext=mov";
NSArray *arr = [urlName componentsSeparatedByString:@"id"];
NSString *str = [arr lastObject];
NSArray *arr1 = [str componentsSeparatedByString:@"&"];
NSLog(@"array is %@",arr1);
NSString *str2 = [[arr1 objectAtIndex:0] substringFromIndex:1];
NSLog(@"str2 is %@",str2);
output will be A3210417-4BAC-1C78-BD93-4BDD286247D9 :)
输出将是A3210417-4BAC-1C78-BD93-4BDD286247D9 :)
#2
0
Try like this:
试试这样:
NSString * urlName = @"assets-library://asset/asset.mov?id=A3210417-4BAC-1C78-BD93-
NSString * urlName = @“assets-library://asset/asset.mov?id = A3210417-4BAC-1C78-BD93-
4BDD286247D9&ext=mov";
NSArray *arr = [urlName componentsSeparatedByString:@"id"];
NSString *str = [arr lastObject];
NSArray *arr1 = [str componentsSeparatedByString:@"&"];
NSLog(@"array is %@",arr1);
NSString *str2 = [[arr1 objectAtIndex:0] substringFromIndex:1];
NSLog(@"str2 is %@",str2);
#1
3
play with the string like this:
玩这样的字符串:
NSString * urlName = @"assets-library://asset/asset.mov?id=A3210417-4BAC-1C78-BD93-
4BDD286247D9&ext=mov";
NSArray *arr = [urlName componentsSeparatedByString:@"id"];
NSString *str = [arr lastObject];
NSArray *arr1 = [str componentsSeparatedByString:@"&"];
NSLog(@"array is %@",arr1);
NSString *str2 = [[arr1 objectAtIndex:0] substringFromIndex:1];
NSLog(@"str2 is %@",str2);
output will be A3210417-4BAC-1C78-BD93-4BDD286247D9 :)
输出将是A3210417-4BAC-1C78-BD93-4BDD286247D9 :)
#2
0
Try like this:
试试这样:
NSString * urlName = @"assets-library://asset/asset.mov?id=A3210417-4BAC-1C78-BD93-
NSString * urlName = @“assets-library://asset/asset.mov?id = A3210417-4BAC-1C78-BD93-
4BDD286247D9&ext=mov";
NSArray *arr = [urlName componentsSeparatedByString:@"id"];
NSString *str = [arr lastObject];
NSArray *arr1 = [str componentsSeparatedByString:@"&"];
NSLog(@"array is %@",arr1);
NSString *str2 = [[arr1 objectAtIndex:0] substringFromIndex:1];
NSLog(@"str2 is %@",str2);