Created
November 12, 2014 11:22
-
-
Save priore/f5b5c3ebf4a3544382e2 to your computer and use it in GitHub Desktop.
How to get duration (HH:MM:SS) from AVAudioPlayer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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