I have two methods below. One method (timerHit) which gets the track duration of the current playing song, minuses 1 from it and prints it out in the log it then also updates a label with the value too. The other method (countDown) which repeats every second calls the timerHit method, however it doesn’t seem to work correctly the NSLog statement works and repeats thus printing the value every second but the update label statement [duration setDoubleValue:trackDuration]; doesn’t work. Can anyone help me?
- (void)countDown {
[NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(timerHit:) userInfo:nil repeats:YES];
}
- (void)timerHit:(NSTimer *)p_timer
{
iTunesApplication *iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
double trackDuration = [[iTunes currentTrack] duration];
if( trackDuration <= 1 && [p_timer isValid] )
[p_timer invalidate];
trackDuration--;
NSLog(@"%d", trackDuration);
[duration setDoubleValue:trackDuration];
}
Thanks, Sami.
Assuming that duration is an instance of NSTextField (After Googling, this seems to be the case – I can’t find NSLabel to be an existing object), try this;