If you're playing your audio with AVPlayer
then you can use its **addPeriodicTimeObserverForInterval**:
method to update your UISlider. For example, if the name of your slider is playerScrubber
:
AVPlayerItem *newPlayerItem = [[AVPlayerItem alloc] initWithAsset:<your asset>];
AVPlayer* player = [[AVPlayer alloc] initWithPlayerItem:newPlayerItem];
CMTime interval = CMTimeMake(33, 1000); // 30fps
id playbackObserver = [player addPeriodicTimeObserverForInterval:interval queue:dispatch_get_current_queue() usingBlock: ^(CMTime time) {
CMTime endTime = CMTimeConvertScale (player.currentItem.asset.duration, player.currentTime.timescale, kCMTimeRoundingMethod_RoundHalfAwayFromZero);
if (CMTimeCompare(endTime, kCMTimeZero) != 0) {
double normalizedTime = (double) player.currentTime.value / (double) endTime.value;
playerScrubber.value = normalizedTime;
}
}];
And later when you're done:
[player removeTimeObserver:playbackObserver];
Goodluck!