Question

Two or three days ago Apple introduced a new updated for iTunes: a new miniplayer, a new player time bar, etc... And I thought: "sweet!". But I found a new issue with it, and here's my problem:

A long time ago, I created the iTunes.h file by typing the following line in the console app

sdef /Applications/iTunes.app | sdp -fh --basename "iTunes"

That's the file I've been using to retrieve data from iTunes using ScriptingBridge. But now, with the new update, calling [iTunes playerPosition] doesn't work properly any more with the newest version, (it still works perfectly with the older version). Now, the NSInteger that I get by calling playerPosition is always 3 (seconds, 0:03) even if the player position is not that.
So I thought, maybe If I generate the iTunes.h file again it will work. And yes, I was right! It works nice but now [iTunes playerPosition] is broken on the older versions and the output is always 0 (seconds, 0:00).

Is there any way to work around this so it works on both older and newer versions?
Thank you!

Note: if you have your iTunes updated, try downloading Significator for iTunes on the Mac App Store to see what I'm talking about.

Était-ce utile?

La solution

Based on the information in the two .h files you are going to have to pay attention to the version of iTunes in order to figure out how to interpret the data coming back. In particular, you'll want to check the build number in the info.plist in the iTunes bundle and based on that use one of the two class interfaces that you have built with sdp. I would suggest that you take the old file and pull out the class and rename it to something with an appended version number, because you're going to need to cast the object pointer before calling the method based on which version of iTunes you are working with.

So, assuming you have ITunesObjectProxy and ITunesObjectProxy_old, you would use:

double progress;
if (newer)
    progress = [iTunes playerPosition ];
else
    progress = (double)[(ITunesProxyObject_old *)iTunes playerPosition ];

That way, you will make sure to get the double and int handled correctly. Obviously, the specific names of your objects and classes may differ and I'm leaving the case of determining the version of iTunes.app to you, but that's a trivial check of the Info.plist.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top