Skip to content

Instantly share code, notes, and snippets.

@priore
Created November 12, 2014 11:22
Show Gist options
  • Save priore/f5b5c3ebf4a3544382e2 to your computer and use it in GitHub Desktop.
Save priore/f5b5c3ebf4a3544382e2 to your computer and use it in GitHub Desktop.
How to get duration (HH:MM:SS) from AVAudioPlayer
// How to get duration (HH:MM:SS) from AVAudioPlayer
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL URLWithString:@"you-url-sreaming"] error:nil];
[audioPlayer prepareToPlay];
CMTime duration = [[[audioPlayer currentItem] asset] duration];
float seconds = CMTimeGetSeconds(duration);
NSLog("Duration : %@", [NSString stringWithFormat:@"%02d:%02d:%02d", (int)((int)(seconds)) / 3600, (int)((int)(seconds)) / 60, (int)((int)(seconds)) % 60]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment