priore

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

Sep 12th, 2014
278
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