1

I'm trying to write ALAsset in a NSData and somehow came up with the following code which does not work. What I would like to know is, whether the code is similar to this? Or is there another way of doing it?

NSData *data = [[NSData alloc] initWithContentsOfFile:@"assets-library://asset/asset.MOV?   id=100000009&ext=MOV" ];
Gavin Miller
  • 43,168
  • 21
  • 122
  • 188
tan
  • 233
  • 2
  • 5
  • 14
  • You are passing a URL string into a method that takes a file path. Did you try ´initWithContentsOfURL´ and passing an NSURL instead? – Max Seelemann Nov 01 '10 at 13:59
  • 1
    `initWithContentsOfURL` of an @"assets-library://..." url will not work -- it will in fact crash. see http://stackoverflow.com/questions/5047643/getting-the-path-of-an-alasset for a better answer. – natbro Jan 28 '12 at 20:17

2 Answers2

2

The defaultRepresentation of an ALAsset has a getBytes:fromOffset:length:error: method. Use that.

Mike
  • 2,399
  • 1
  • 20
  • 26
0

There's a space between your "?" and "id=.." is this the problem?

The best way to debug this is to first try opening that file you name (or creating an NSURL and using initWithContentsOfURL as suggested by Max) and then running the debugger, checking whether that succeeds. Right now you're debugging a few things simultaneously, break out that compound statement and figure out what could be going wrong

Nektarios
  • 10,173
  • 8
  • 63
  • 93