Audio - Jump Forward 30 Seconds

删除回忆录丶 提交于 2019-12-06 08:19:13

in swift 3:

player.play()
player.currentTime=60

unit is second no need to stop at all

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.

How about something like this?

@IBAction func skipForward30SecondsPressed(sender: AnyObject) {

    var currentTime = audioPlayer.currentTime

    audioPlayer.stop()

    audioPlayer.playAtTime(currentTime + 30.0) // plus 30 seconds
}

Get the current time of the player and plus 30s to the current time.Then make the palyer play at the time (current time + 30).

var currentTime  = player.currentTime
player.playAtTime(currentTime + 30.0)

If you want to use a slider to change the currentTime, you can use player.currentTime = TimeInterval(slider.value) * player.duration to get it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!