Reputation: 71
I'm using AVPlayer. And I want to get current time of player to show for user. The problem is the string getting wrong value from NSDate you can see in images
This is date value
And this string value getting from date
please help to solve. this is my code
NSDate* d = [NSDate dateWithTimeIntervalSince1970:CMTimeGetSeconds(mPlayer.currentTime)];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
[dateFormatter setDateFormat:@"mm:ss"];
NSString* result = [dateFormatter stringFromDate:d];
avPlayerLabel.text = result;
Upvotes: 1
Views: 73
Reputation: 9731
You don't even need an NSDateFormatter
:
Float64 time = CMTimeGetSeconds(mPlayer.currentTime) + 0.5;
unsigned minutes = (unsigned)time / 60;
unsigned seconds = (unsigned)time % 60;
avPlayerLabel.text = [NSString stringWithFormat:@"%02u:%02u", minutes, seconds];
Upvotes: 2