Вопрос

I obtain the URL of an AVURLAsset like this:

NSURL *url = [[asset defaultRepresentation] url];

In console, the AVURLAsset's url looks like this:

assets-library://asset/asset.mov?id=A3210417-4BAC-1C78-BD93-4BDD286247D9&ext=mov

I tried getting file name with extension from URL like this:

NSString *last = [[url URLByDeletingPathExtension] lastPathComponent];
NSString *tnFileName = [NSString stringWithFormat:@"%@_tn.%@", last, url.pathExtension];

Here is console log of tnFileName:

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?

To clarify, I need this to store thumbnails to disk and I want to use a name that matches the asset.

Это было полезно?

Решение

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 :)

Другие советы

Try 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);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top