0

So I am using UISlider for an Audio Player's scrubber. What I am attempting to do is update a label whenever a UISlider's value is changed so that it can properly display the current audio's time elapsed in minutes and seconds. Here is my current code:

- (IBAction)valueChanged:(id)sender {
    if (!self.scrubbing) {
        [[CRAudioUtility sharedUtility]seekToTime:self.progressSlider.value];
        NSInteger value    = [CRAudioUtility sharedManager].currentPlaybackTime;
        NSInteger minutes    = value / 60;
        NSInteger seconds = value % 60;

        NSString *time_stamp = [NSString stringWithFormat:@"%d hours:%d minutes",minutes,seconds];
        [self.progressSlider setAccessibilityValue:time_stamp];
        self.progressSliderLabel.text = [NSString stringWithFormat:@"%d:%d minutes",minutes,seconds;

    }
}

Audio items may or may not be longer than an hour, and the length may be more than one hour.

Since the accessibilityLabel is announced, I need to ensure that the word "hour" is announced properly in their singular or plural format. What kind of solutions can I do to handle this case?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
3254523
  • 3,016
  • 7
  • 29
  • 43

1 Answers1

1

What kind of solutions can I do to handle this case?

Seems like you'd just want to consider the various possibilities separately:

if (minutes > 120) {
    time_stamp = [NSString stringWithFormat:@"%d hours:%d minutes", minutes / 60, minutes % 60];
}
else if (minutes > 60) {
    time_stamp = [NSString stringWithFormat:@"1 hour:%d minutes", minutes % 60];
}
else {
    time_stamp = [NSString stringWithFormat:@"%d:%d minutes", minutes, seconds];
}
Caleb
  • 124,013
  • 19
  • 183
  • 272
  • I wont down vote this but it is not the right way and not feasible with X language/region settings(!) and X combinations (e.g. adding seconds and considering singular and plural for minutes and seconds too :) – Daij-Djan Dec 16 '17 at 00:24
  • I don't know a better option :D I will end up with sth like this... :P – Daij-Djan Dec 16 '17 at 00:32
  • If using Swift, you could use a switch statement with where clauses to check each condition, which might look a bit neater, but the logic would still be similar. – Caleb Dec 16 '17 at 05:14