0

I've got the following code tied to a 'Jump Forward' button:

@IBAction func jumpForwardPressed(sender: AnyObject) {
    var currentTime = audioPlayer.currentTime
    var playForwardSkip = NSTimeInterval()
    audioPlayer.stop()
    audioPlayer.prepareToPlay()
    playForwardSkip = 3.0 // skip forward 3 seconds

    var skipF = currentTime + playForwardSkip
    println("currentTime:\(currentTime) and playForwardSkip:\(playForwardSkip) and skipF:\(skipF)")

    audioPlayer.playAtTime(skipF)

When button is pressed, audio stops, console reads out correct 'skipF' to skip to but audio does not play at that new point in time. It does not play at all.

Any pointers as to what might be wrong with my code?

J. Dorais
  • 97
  • 1
  • 11

1 Answers1

0

You have misread the docs. playAtTime: does not seek to a later time in a sound file. It delays the start of playing the sound file (from the start).

To play from the middle of a sound file, set the player's currentTime and start playing.

matt
  • 515,959
  • 87
  • 875
  • 1,141