Atul Atul - 1 month ago 21
iOS Question

How to set current time and total time for a song in AVPlayer?

I want to use the following code in my application to get the current playing time and total time on a UISlider and i get ths code from this link.


CMTime newTime = CMTimeMakeWithSeconds(seeker.value, 1);
[self.player seekToTime:newTime];


sliderTimer = [[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateSlider) userInfo:nil repeats:YES]retain];
self.seeker.maximumValue = [self durationInSeconds];
[seeker addTarget:self action:@selector(sliding:) forControlEvents:UIControlEventValueChanged];
seeker.minimumValue = 0.0;
seeker.continuous = YES;

- (void)updateSlider {

self.seeker.maximumValue = [self durationInSeconds];
self.seeker.value = [self currentTimeInSeconds];

- (Float64)durationInSeconds {
Float64 dur = CMTimeGetSeconds(duration);
return dur;

- (Float64)currentTimeInSeconds {
Float64 dur = CMTimeGetSeconds([self.player currentTime]);
return dur;

But I don't know what is seeker. I am new in iOS and i need help any suggestion any tutorial for this problem.

@property (strong, nonatomic) IBOutlet UISlider *seeker;