I have implemented scrubbing using UISlider the problem is when the song is being played the slider doesnt initiate automatically ,it starts moving only when i tap on it and when the next song starts playing it moves automatically . i want the slider to move when the song starts playing ,this is the code which i am using and one more thing when i move the slider the song has to fast forward .I have added the code which i have written .can anyone help me out .Thanks
-(IBAction)slider:(id)sender
{
CMTime interval = CMTimeMake(33, 1000);
self.playbackObserver = [myPlayer addPeriodicTimeObserverForInterval:interval queue:dispatch_get_current_queue() usingBlock:^(CMTime time) {
CMTime endTime = CMTimeConvertScale (myPlayer.currentItem.asset.duration, myPlayer.currentTime.timescale, kCMTimeRoundingMethod_RoundHalfAwayFromZero);
if (CMTimeCompare(endTime, kCMTimeZero) != 0) {
double normalizedTime = (double) myPlayer.currentTime.value / (double) endTime.value;
self.timeSlider.value = normalizedTime;
}
Float64 currentSeconds = CMTimeGetSeconds(myPlayer.currentTime);
int mins = currentSeconds/60.0;
int secs = fmodf(currentSeconds, 60.0);
NSString *minsString = mins < 10 ? [NSString stringWithFormat:@"0%d", mins] : [NSString stringWithFormat:@"%d", mins];
NSString *secsString = secs < 10 ? [NSString stringWithFormat:@"0%d", secs] : [NSString stringWithFormat:@"%d", secs];
currentTimeLabel.text = [NSString stringWithFormat:@"%@:%@", minsString, secsString];
}];
}
EDIT
can u explain where am i going wrong
-(IBAction)playButtonPressed:(UIButton *)sender
{
CMTime interval = CMTimeMake(33, 1000);
self.playbackObserver = [myPlayer addPeriodicTimeObserverForInterval:interval queue:dispatch_get_current_queue() usingBlock:^(CMTime time)
{
CMTime endTime = CMTimeConvertScale (myPlayer.currentItem.asset.duration, myPlayer.currentTime.timescale, kCMTimeRoundingMethod_RoundHalfAwayFromZero);
if (CMTimeCompare(endTime, kCMTimeZero) != 0) {
double normalizedTime = (double) myPlayer.currentTime.value / (double) endTime.value;
self.timeSlider.value = normalizedTime;
}
}];
[myPlayer play];
}
-(IBAction)slider:(id)sender
{
Float64 currentSeconds = CMTimeGetSeconds(myPlayer.currentTime);
int mins = currentSeconds/60.0;
int secs = fmodf(currentSeconds, 60.0);
NSString *minsString = mins < 10 ? [NSString stringWithFormat:@"0%d", mins] : [NSString stringWithFormat:@"%d", mins];
NSString *secsString = secs < 10 ? [NSString stringWithFormat:@"0%d", secs] : [NSString stringWithFormat:@"%d", secs];
currentTimeLabel.text = [NSString stringWithFormat:@"%@:%@", minsString, secsString];
}