Loading local resources from an app

psonice's picture

I've hit a rather nasty issue. If you load resources from disk within a composition, then embed the composition in an application, the resources don't get always get loaded. Some examples:

Images loaded with image importer seem to be fine. Images loaded with image downloader don't work. Movies loaded with movie downloader don't work.

Image can be worked around, but movies are a bit more awkward. The problem is with the path - anything with a full path (e.g. /Users/psonice/my.app/Contents/Resources/video.mov) will work, but that's useless if your app gets moved around. I've tried pretty much every combination of relative paths (./video.mov, video.mov, ../video.mov) and tried putting the video in every location where it could point to, to no avail.

So, what's the best way to work around it?

cwright's picture
bug reporter?

see http://kineme.net/BugReports/CompositionRelativeAddressing for some issues with this even in the days of Tiger.

If it's a problem with our patches (this happens from time to time; the code to "unwind" paths is ugly, and platform specific), yell at me and I'll tweak stuff into working. If it's one of Apple's patches, file a bug report, or yell at us to make a "path sanitizer" patch that handles weird cases like this?

One of the problems (other than ugly, platform specific code) is that the environment isn't always told about its path (external applications don't always set up an environment identically to QC, which does tell you this information) -- I can do some tests to try to see the extent of this issue (ideally, QCComposition should be able to figure it out automatically since you give it a path to load the composition from; I'm not sure if you need to specify it again later on when you render it).

Image Importer doesn't "load" stuff in the classical sense; it embeds the image into the composition. Image and Movie Downloader, in contrast, don't bloat the compo by embedding info inside.

Safest for the time being is absolute paths; everything supports those.

psonice's picture
Thanks, looks good

I wondered what image importer did - I suspected it might embed the file, but decided that it didn't because the file size didn't increase. I was looking at the disk usage though, and I guess the image I used wasn't enough to push the file size into the next block.

For now, I'm using fixed paths, but it makes me feel dirty insisting that people run my app from a fixed location :( On the other hand, Toby's spark titler looks to contain exactly what I need :)

I'll give it a quick test later, and find out.

cwright's picture
unfixed location

You can also get away with not using a fixed location, by having the composition take a string input somewhere that for the base of the path (/Users/someuser/Desktop/, for example) -- the application can provide this value pretty easily ([[NSBundle mainBundle] resourcePath] or something similar). Then you just need some (admittedly ugly) string printers to add on the special parts.

If Toby's app does indeed do what you're needing, please let us know -- I think it worked for Tiger, but I've not tried it on Leopard (or, maybe I'm really confused, and it was the other way around?). A few extra lines of code posted somewhere to correct this would be a handy snippet to have :)

psonice's picture
Spark: no go. Jumble of extra path handling patches: go.

I couldn't get Toby's method to work. It may have been some silly typo or something (no build errors though), i don't know.. not knowing how to find out within QC what the local path is doesn't help, but it didn't appear to make any difference.

Eventually, I did as you suggested and passed NSbundle mainbundle to a string input, and used string printer to build the full path for each file. 4 pieces of music, and one pdf in total, so it wasn't too painful :)

Which reminds me, image importer will load a PDF but it didn't seem to embed it in the composition like it does for images. Might have been my mistake again, but it's something to watch out for if you're doing this kind of stuff.