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

priore Sep 12th, 2014 262 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
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand