在30FPS中每帧编写XML行

时间:2013-01-19 00:24:25

标签: objective-c xml cocoa

这是我的代码:

float timeInterval = 1 / [frameRateTextField floatValue];

        recordingTimer = [NSTimer scheduledTimerWithTimeInterval:timeInterval
                                                          target:self
                                                        selector:@selector(recordingTimerSelector:)
                                                        userInfo:nil
                                                         repeats:YES];


- (void) recordingTimerSelector:(NSTimer*)timer{
    NSXMLElement *timecode = [[NSXMLElement alloc] initWithName:@"timecode"];
    [timecode setStringValue:[NSString stringWithFormat:@"%@,%@,%@,%@,%@",[DMXChannelArray objectAtIndex:0], [DMXChannelArray objectAtIndex:1], [DMXChannelArray objectAtIndex:2], [DMXChannelArray objectAtIndex:3], [DMXChannelArray objectAtIndex:4]]];

    [root addChild:timecode];

    time = time + 1;
    [theRecordingTime setStringValue:[NSString stringWithFormat:@"%d", time]];
}

这是最好的方法吗?我基本上制作了一个分辨率为30FPS的“录音机”。有没有办法让它与实际时间一致,而不是一个单独的实体?它可能会使它更准确。像:

10:40:41.0 - record element
10:40:41.3 - record element
10:40:41.6 - record element

谢谢!

1 个答案:

答案 0 :(得分:0)

你可以get the current number of seconds since the reference date by asking NSDate for it

在启动计时器时获取该时间间隔,然后每次启动计时器,并从当前计时器中减去开始时间间隔,以获得自启动以来的秒数。