您可以记录开始日期和结束日期,然后比较日期以查看视频播放了多长时间。
日期也包括时间。
所以:
1)当用户按下播放时,你可以去:
NSDate *startPlayDate = [NSDate date];
2)当用户停止视频时,你可以去:
NSDate *stopPlayDate = [NSDate date];
3)现在比较两个日期的差异,您应该看到用户播放视频的秒数:
NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];
NSDateComponents* components = [gregorianCalendar components: NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit
fromDate:startPlayDate
toDate:stopPlayDate
options:0] ;
NSString *message = [[NSString alloc] initWithFormat:@"Video played for: %d hours, %d minutes, %d seconds", components.hour, components.minute, components.second];
UIAlert *alert = [[UIAlertView alloc] initWithTitle:@"Duration"
message:message
delegate:self
cancelButton:@"OK"
otherButton:nil, nil];
[alert show];
那是你要找的吗?