Lefora Free Forum
login join
Loading
1467 views

help: how to implement a timer/thread/runloop?

Page 1
1–6
rookie - member
5 posts

i am writing a basic app to display the name of current song playing in iTunes.
I have an NSTextField to output to a Label, and a function that gets the name from iTunes.

I am looking for a way to automate the process. I want the app to fetch the name every 1 sec or when the song changes.

Whats the way to go here?

thanks

rookie - member
3 posts

You need to set up an observation.  NSNotificationCenter is what you're looking for.

[[NSNotificationCenter defaultCenter] addObserver:(id)notificationObserver selector:(SEL)notificationSelector name:(NSString *)notificationName object:(id)notificationSender]

Look in the iTunes.h file to get the correct name of the observation.  Have the selector change the NSTextField.

rookie - member
5 posts

Thank you very much!
I will try that today.

rookie - member
5 posts

I managed to try some notifications, and they worked.
Should I have the object of the notification point to itunes current track?
Because I tried that but didn't work.

Here is the itunes.h in .h and .txt.

http://dl.dropbox.com/u/349788/iTunes.h
http://dl.dropbox.com/u/349788/iTunes.txt

What should I point?

rookie - member
3 posts

    In your header declare iTunes as iTunesApplication and trackInfo as iTunesTrack. (iTunesApplication *iTunes, etc.)


    iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];

    [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(updateData) name:@"com.apple.iTunes.playerInfo" object:nil];


In my updateData, I have this.


trackInfo = [iTunes currentTrack];


This takes the current track info and stores it in a variable.  From that, I can use trackInfo for all the information.


[trackInfo name]

[trackInfo album]

[trackInfo artist]

rookie - member
5 posts

again.... huuuuuuuge thanks...

btw.. where do you find that info? where did you find the com.apple.iTunes.playerInfo ?

is there a place to consult?

thanks one more time!

Page 1
1–6

Locked Topic


You must be a member to post in this forum

Join Now!