In this tutorial I teach you how to add a duration slider that will allow the user to choose the time that the song plays from in your app.
Main Code:
In .h:
IBOutlet UISlider *positionSlider;
NSTimer *soundTimer;
(IBAction)changePosition;
(void) updateSlider;
In .m in viewDidLoad:
soundTimer = nil;
positionSlider.maximumValue = sound.duration;
positionSlider.minimumValue = 0;
sound.currentTime = positionSlider.value;
(IBAction)changePosition {
sound.currentTime = positionSlider.value;
}
(void) updateSlider {
[positionSlider setValue:sound.currentTime];
}
in playSound:
if (![sound isPlaying]) {
if (soundTimer == nil)
soundTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateSlider) userInfo:nil repeats:YES];
} else {
[soundTimer invalidate];
soundTimer = nil;
}
In resetSound:
positionSlider.value = sound.currentTime;
[soundTimer invalidate];
soundTimer = nil;
Twitter: / failcakeapps
Apple Developer Center: http://developer.apple.com/devcenter/...
Website: http://failcake.webs.com/
Channel: / milmersxcode