Feeds

Serve up iTunes with Apple's media browser

Give your software some soul

5 things you didn’t know about cloud backup

Mac Secrets Let's stay with the iLifeMediaBrowser.framework, which we looked at last time. Previously, I showed how to use Apple's built-in media browser using virtually no code.

Following on from that, a number of folks have asked me if it's possible to use classes in the iLifeMediaBrowser library to access your iTunes library without displaying the Apple browser? Indeed it is, and this is the subject of this article.

First off, why would you want to do this? From a developer's point of view, there are lots of good reasons. Maybe you've written an alarm-clock utility and you want the user to be able to choose a "wake-up" song from her iTunes library. Or maybe you're writing an app to backup, consolidate or repair the song library. Or maybe you want multiple iTunes libraries - whatever.

If you browse the net, you'll find various techniques for interrogating the library, ranging from using iTunes with AppleScript to parsing the associated XML file. But to the best of my knowledge, the techniques used here have never been documented outside of Apple.

The key class that I'm using here is called ILiTunesMediaManager. As the name suggests, this class is the media manager for iTunes. If your interest lies elsewhere, there are equivalent classes that handle the media for other iLife applications, such as ILiMovieMediaManager and ILiPhotoMediaManager.

Instantiating an ILiTunesMediaManager object is dead easy. We simply call the sharedMediaManager class method like this:


ILiTunesMediaManager * tunesManager = [ILiTunesMediaManager sharedMediaManager];

As before, I've provided the necessary header files as part of this month's sample project. The header files were created using class-dump as described in previous articles.

Load your data

Once we've got an instance of ILiTunesMediaManager, we need to load it with data from the iTunes library: this doesn't happen automatically. To do this, you need to call the loadData method. This is asynchronous - it works away in the background - so we need some way of knowing when the job's done.

From our perspective, the simplest way of doing this is to set up a timer to periodically query the media manager to ask if it's ready yet. This can be done via the isLoaded and isLoading methods: I check them both just to make sure the media manager really is ready. If you're worried about long delays here, don't be: I've got over 1,600 songs in my library, and it loads almost instantly.

Once ILiTunesMediaManager is ready to roll, we can start having some fun. The list of available playlists is accessed, counter-intuitively, via a method called playlists.

Gartner critical capabilities for enterprise endpoint backup

More from The Register

next story
Why has the web gone to hell? Market chaos and HUMAN NATURE
Tim Berners-Lee isn't happy, but we should be
Apple promises to lift Curse of the Drained iPhone 5 Battery
Have you tried turning it off and...? Never mind, here's a replacement
'Stop dissing Google or quit': OK, I quit, says Code Club co-founder
And now a message from our sponsors: 'STFU or else'
Microsoft boots 1,500 dodgy apps from the Windows Store
DEVELOPERS! DEVELOPERS! DEVELOPERS! Naughty, misleading developers!
Linux turns 23 and Linus Torvalds celebrates as only he can
No, not with swearing, but by controlling the release cycle
Scratched PC-dispatch patch patched, hatched in batch rematch
Windows security update fixed after triggering blue screens (and screams) of death
This is how I set about making a fortune with my own startup
Would you leave your well-paid job to chase your dream?
prev story

Whitepapers

Best practices for enterprise data
Discussing how technology providers have innovated in order to solve new challenges, creating a new framework for enterprise data.
Implementing global e-invoicing with guaranteed legal certainty
Explaining the role local tax compliance plays in successful supply chain management and e-business and how leading global brands are addressing this.
Advanced data protection for your virtualized environments
Find a natural fit for optimizing protection for the often resource-constrained data protection process found in virtual environments.
How modern custom applications can spur business growth
Learn how to create, deploy and manage custom applications without consuming or expanding the need for scarce, expensive IT resources.
High Performance for All
While HPC is not new, it has traditionally been seen as a specialist area – is it now geared up to meet more mainstream requirements?