0

I found similar questions here, here, and here but with none of the answers I have been able to solve the problem. Simply put, the audio does not jump at a specific moment but instead starts from scratch.

func seekTo(time: Double) {
    player.stop()
    
    let startSample = Double(time * audioSampleRate)
    let lengthSamples: AVAudioFramePosition = AVAudioFramePosition(Double(audioLengthSamples) - startSample)
    let frameCount = AVAudioFrameCount(audioLengthSamples - lengthSamples)
    
    if currentPosition < audioLengthSamples {
        player.scheduleSegment(audioFile!, startingFrame: AVAudioFramePosition(startSample), frameCount: AVAudioFrameCount(frameCount), at: nil, completionHandler: nil)
        
        let wasPlaying = player.isPlaying
        if wasPlaying {
            player.play()
        }
    }
}

The time variable is where it receives the specific time to which the audio should skip. Any help?

Vivek Lele
  • 109
  • 4
LucasC
  • 43
  • 5

0 Answers0