实际上,当歌曲在AVAudioPlayer中播放时,我做到了,Slider随着歌曲的运行而进步。我也是这样做的,如果我向它前进或后退,从那个位置播放当前的歌曲。 但问题是在寻找滑块到特定位置后它没有进展并停在那里但是歌曲仍然从该位置开始运行。
以下代码:
块引用
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:)];
}
块引用