priore

How to get duration (HH:MM:SS) from AVAudioPlayer

Sep 12th, 2014
323
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // How to get duration (HH:MM:SS) from AVAudioPlayer
  2. AVAudioPlayer *audioPlayer =  [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL URLWithString:@"you-url-sreaming"] error:nil];
  3. [audioPlayer prepareToPlay];
  4. CMTime duration = [[[audioPlayer currentItem] asset] duration];
  5. float seconds = CMTimeGetSeconds(duration);
  6. NSLog("Duration : %@", [NSString stringWithFormat:@"%02d:%02d:%02d", (int)((int)(seconds)) / 3600, (int)((int)(seconds)) / 60, (int)((int)(seconds)) % 60]);
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×