Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Audio - Jump Forward 30 Seconds

I've got an audio player that plays audio retrieved from Core Date. Play & pause work fine. I'm trying to implement a 'Jump Forward 30 Seconds' button and seeking any pointers as to how I would go about that.

Code for my 'Play/pause' button

@IBAction func playPressed(sender: AnyObject) { 

    let play = UIImage(named: "play")
    let pause = UIImage(named: "pause")
    if audioPlayer.playing {
        pauseAudioPlayer()
        audioPlayer.playing ? "\(playButton.setImage( pause, forState: UIControlState.Normal))" : "\(playButton.setImage(play , forState: UIControlState.Normal))"

    }else{
        playAudio()
        audioPlayer.playing ? "\(playButton.setImage( pause, forState: UIControlState.Normal))" : "\(playButton.setImage(play , forState: UIControlState.Normal))"
    }

}
like image 852
J. Dorais Avatar asked Feb 01 '26 16:02

J. Dorais


2 Answers

in swift 3:

player.play()
player.currentTime=60

unit is second no need to stop at all

like image 171
Martian2049 Avatar answered Feb 04 '26 04:02

Martian2049


For iOS we need to use CMTime. Only CMTime can be fed to the player in order to jump forward or backward from current position. Now current stream position if the player is running any stream can be had using currentTime property of the player.

Good Luck. Let me know if you have any further questions on this.

like image 27
learner Avatar answered Feb 04 '26 04:02

learner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!