0

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.

openfrog
  • 40,201
  • 65
  • 225
  • 373

2 Answers2

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

PR Singh
  • 653
  • 5
  • 15
0

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);
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56
  • To be perfectly honest, shelling out with NSTask to perform some string manipulation seems a pretty crazy thing to do. – Mike Abdullah Oct 06 '13 at 19:28
  • Yes Correct, But the result execution will be very fast using shell script. – Hussain Shabbir Oct 07 '13 at 04:31
  • No, it will be slow compared to doing it in-process, unless you write some terrible code – Mike Abdullah Oct 07 '13 at 12:12
  • My point is if having large amount of data then it will be fast – Hussain Shabbir Oct 07 '13 at 12:36
  • 2
    It really won't. Using NSTask inherently carries the overhead of packaging up the string suitable for passing across process boundaries, and firing up that new process. The app can perform string processing as fast as any external task, and without the overhead I've just described. Cocoa ships with an extensive suite of string manipulation facilities. Learn them. **Use them**. – Mike Abdullah Oct 07 '13 at 14:24