0
votes

In a Music Playing app (tracks from a url, using STKAudioPlayer by tumtumtum) i added a UISlider to the Music player view controller, i handled the slidervaluechanged method to make the audio player seek to a particular playback time, then i set the continuous property of the UISlider to YES in viewDidLoad, but when the music plays the thumb image of the slider doesn’t move, it’s static while the song is playing, unlike other music players where the slider thumb moves as the time changes to show progress. does anyone have any idea what i could be doing wrong? This is what i've done

self.progressSlider.continuous = YES;
[self.progressSlider setValue:self.audioPlayer.progress animated:YES];

if (!audioPlayer) {
        self.progressSlider.value = 0;
        self.streamStatus.text = @"";
        return;
    }
    if (audioPlayer.duration != 0) {

        self.progressSlider.minimumValue = 0;
        self.progressSlider.maximumValue = audioPlayer.duration;
        self.progressTimer.text = [NSString stringWithFormat:@"%@", [self formatTimeFromSeconds:audioPlayer.progress]];
        self.musicLength.text = [NSString stringWithFormat:@"%@", [self formatTimeFromSeconds:audioPlayer.duration]];
    }

and this:

-(NSString*) formatTimeFromSeconds:(int)totalSeconds

{

int seconds = totalSeconds % 60;
int minutes = (totalSeconds / 60) % 60;

return [NSString stringWithFormat:@"%02d:%02d", minutes, seconds];

}

-(void) setupTimer { timer = [NSTimer timerWithTimeInterval:0.001 target:self selector:@selector(ticker) userInfo:nil repeats:YES];

[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];

}

1
can you add the funcion formatTimeFromSeconds?jose920405
You have to update the value yourself, the slider won't magically know to update the value while the player is playing. Use an NSTimer or something like that and update the timer every second or half a second while your player is playing.EmilioPelaez
how exactly do i do that?T. Israel
-(void) setupTimer { timer = [NSTimer timerWithTimeInterval:0.001 target:self selector:@selector(tick) userInfo:nil repeats:YES]; [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]; }T. Israel
did this but still isnt workingT. Israel

1 Answers

0
votes

I think you should use the current time and not the duration.

Try

[labelTime setText:[NSString stringWithFormat:@"%i:%.02i", (int)(CMTimeGetSeconds(audioPlayer.currentTime) / 60), (int)CMTimeGetSeconds(audioPlayer.currentTime) % 60]];