Use UISlider with AVAudioPlayer playAtTime: method, there is no built-in search bar for AVAudioPlayer.
Check out this sample code, it implements what you want in the avTouchController class
https://developer.apple.com/library/ios/samplecode/avTouch/Introduction/Intro.html
add a UISLider to you interface and bind valueChanged: to the seekTime method:
in .h
@property (nonatomic, weak) IBOutlet UISlider *seekbar; @property (nonatomic, strong) AVAudioPlayer *audioPlayer; @property (nonatomic, strong) NSTimer *updateTimer;
in .m in viewDidLoad after loading AVAudioPlayer,
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: [[NSBundle mainBundle] pathForResource:@"There A Long, Long Trail A-Winding" ofType:@"mp3"]]; AVAudioPlayer *audio = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil]; self.audioPlayer = audio; self.seekbar.minimumValue = 0; self.seekbar.maximumValue = self.audioPlayer.duration; [[self audioPlayer] play]; self.updateTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(updateSeekBar) userInfo:nil repeats:YES]
and add the following method
- (void)updateSeekBar{ float progress = self.audioPlayer.currentTime; [self.seekbar setValue:progress]; } - (IBAction)seekTime:(id)sender { self.audioPlayer.currentTime = self.seekbar.value; }
ManicMonkOnMac
source share