Mehul Solanki
Mehul Solanki

Reputation: 463

How to make progressive UISlider like UIProgressView in AVAudioPlayer as song is being playing?

Actually i made that while song is playing in AVAudioPlayer, Slider is progressed as song running. Also i made if i seek it to forward or backward, from that position current song is playing. But the problem is after seeking the slider to particular position it not progressed and stop there but still song is running from that position.

The code below :

Blockquote

myTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self     selector:@selector(updateMyProgressOfCurrentPlayingSong:) userInfo:nil repeats:YES];

-(void)updateMyProgressOfCurrentPlayingSong:(NSTimer *)theTimer{
//For Current Song Playing Slider
float progr = [mediaPlayer currentTime]/[mediaPlayer duration];
self.audioCurrentPlayingSlider.value = progr;
}

//For Slider Value change
-(IBAction)audioCurrentSongPlayingSlider:(id)sender {
 [myTimer invalidate];
 myTimer = nil;
 [self.audioCurrentPlayingSlider setMinimumValue:0.0];
 [self.audioCurrentPlayingSlider setMaximumValue:[mediaPlayer duration]];
 [mediaPlayer setCurrentTime:[self.audioCurrentPlayingSlider value]];      
 [myTimer methodForSelector:@selector(updateMyProgressOfCurrentPlayingSong:)];

}

Blockquote

Upvotes: 0

Views: 3691

Answers (1)

Related Questions