Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Shouldn't be a problem - just set the slider to continuous and set the max value to your player's duration after loading your sound file.</p> <p><strong>Edit</strong></p> <p>I just did this and it works for me...</p> <pre><code>- (IBAction)slide { player.currentTime = slider.value; } - (void)updateTime:(NSTimer *)timer { slider.value = player.currentTime; } - (IBAction)play:(id)sender { NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"sound.caf" ofType:nil]]; NSError *error; player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&amp;error]; if (!player) NSLog(@"Error: %@", error); [player prepareToPlay]; slider.maximumValue = [player duration]; slider.value = 0.0; [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTime:) userInfo:nil repeats:YES]; [player play]; } </code></pre> <p>The slider is configured in IB, as is a button to start playing.</p> <h2>Swift 3.0 Update:</h2> <pre><code>var player: AVAudioPlayer! var sliderr: UISlider! @IBAction func play(_ sender: Any) { var url = URL(fileURLWithPath: Bundle.main.path(forResource: "sound.caf", ofType: nil)!) var error: Error? do { player = try AVAudioPlayer(contentsOf: url) } catch let error { } if player == nil { print("Error: \(error)") } player.prepareToPlay() sliderr.maximumValue = Float(player.duration) sliderr.value = 0.0 Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(self.updateTime), userInfo: nil, repeats: true) player.play() } func updateTime(_ timer: Timer) { sliderr.value = Float(player.currentTime) } @IBAction func slide(_ slider: UISlider) { player.currentTime = TimeInterval(slider.value) } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload