One of the OS 3.0 upgrades we were psyched about was iPod integration. I’ve been playing around with it a lot for several of our upcoming projects, and I have some comments that might help people doing the same.
When you use the iPod app, every tab looks amazing and scrolls smoothly. When you first setup your own music browser, however, you’ll see serious lagging and bad scrolling speeds in your UITableView.
The reason for this is that, even though you might have an MPMediaItemCollection, you don’t actually have the MPMediaItems in memory. So when you query a bunch for MPMediaItemPropertyArtist, for example, you’re going to see serious lagging and it loads that data into memory.
Apple, I’m guessing, prefetches and caches everything, so if you want to see smooth scrolling you should probably do the same. Once you load an MPMediaItem into memory once it stays there and every subsequent request to it is lightening fast.
I today came up with an easy prefetch that rests somewhere between hacky and elegant. I put something like this off the main thread after launch.
MPMediaItem *rItem;
NSString *pID, *title, *artist;
for(int i = 0; i < [query.collections count]; i++) {
rItem = [[query.collections objectAtIndex:i] representativeItem];
pID = [rItem valueForProperty:MPMediaItemPropertyPersistentID];
title = [rItem valueForProperty:MPMediaItemPropertyAlbumTitle];
artist = [rItem valueForProperty:MPMediaItemPropertyArtist];
}
Note that you're not actually storing anything, just calling the item up into memory to query it. What's nice about this solution is that, if your prefetch gets to an item first, your table's request for that information will go lightening fast and thus provide smooth scrolling. If, however, your user gets there first, then the table will lag a little (which is unavoidable) but when the prefetch gets there it won't waste time pulling it into memory again.
Hey,
Could you release the class?
Best regards ;)