fast forwarding a song using AVAudioPlayer

前端 未结 2 1911
故里飘歌
故里飘歌 2021-01-02 20:16

I am creating an audio player application, i need to enable the user to fast forward and backward a song by holding a button(seperately for each). I\'ve done for playing, st

2条回答
  •  心在旅途
    2021-01-02 21:01

    In swift 4

    for forward

    var timeForward = audioPlayer.currentTime
            timeForward += 10.0 // forward 10 secs
            if (timeForward > audioPlayer.duration) {
                audioPlayer.currentTime = timeForward
            } else {
                audioPlayer.currentTime = audioPlayer.duration
            }
    

    for backward

    var timeBack = audioPlayer.currentTime
            timeBack -= 10.0 //backward 10 secs
            if (timeBack > 0) {
                audioPlayer.currentTime = timeBack
            } else {
                audioPlayer.currentTime = 0
            }
    

    Hope this will help.

提交回复
热议问题