1

My iPhone app plays streamed audio from the Internet and I have an UISlider to scrub back and forth the already downloaded file.

This UISlider has transparent tracks, and is on top of an UIProgressView.

The UIProgressView shows the user the streamed audio download progress.

Everything works fine, but I can't figure out how to limit the scrubbing capability not beyond the already downloaded audio file, represented by this UIProgressView.

Any suggestions are welcome.

neowinston
  • 7,584
  • 10
  • 52
  • 83

1 Answers1

4

You can check if the value changed is greater than the progress then set it to the progress. Say you're handling UISlider's UIControlEventValueChanged event in this method,

- (void)valueChanged:(UISlider *)sender {
    if ( self.slider.value > self.progressView.progress ) {
        [self.slider setValue:self.progressView.progress animated:YES];
    }
}

or change the frame based on the progress.

Deepak Danduprolu
  • 44,595
  • 12
  • 101
  • 105
  • Thanks a lot! You saved me a lot of time and spared me from frustation trying to figure this out by myself. Another thing that maybe you could help me. Sometimes when I try to read the latest audio packet I'm getting -1 value, which makes the slider go to zero value, stopping the audio that is playing. How do I always backup the latest packet (in C or Objective-C) before it turns to -1 when it is lost? – neowinston Jun 15 '11 at 13:57
  • Depends on the data type. I will declare an instance variable of that data type and change it for every valid value I receive. So that it will have the latest packet when I want it as in this case when I receive -1. – Deepak Danduprolu Jun 16 '11 at 19:36