add fast forwarding and rewinding

This commit is contained in:
tibbi 2020-04-01 18:13:25 +02:00
parent ed7ff4d9fe
commit 0173a8e4aa
1 changed files with 21 additions and 0 deletions

View File

@ -22,6 +22,8 @@ import java.util.*
import kotlin.collections.ArrayList
class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) {
private val FAST_FORWARD_SKIP_MS = 10000
private var player: MediaPlayer? = null
private var progressTimer = Timer()
@ -58,6 +60,14 @@ class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPager
play_pause_btn.setOnClickListener {
togglePlayPause()
}
player_progress_current.setOnClickListener {
skip(false)
}
player_progress_max.setOnClickListener {
skip(true)
}
}
@SuppressLint("InlinedApi")
@ -201,6 +211,17 @@ class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPager
play_pause_btn.setImageDrawable(drawable)
}
private fun skip(forward: Boolean) {
val curr = player?.currentPosition ?: return
var newProgress = if (forward) curr + FAST_FORWARD_SKIP_MS else curr - FAST_FORWARD_SKIP_MS
if (newProgress > player!!.duration) {
newProgress = player!!.duration
}
player!!.seekTo(newProgress)
resumeSong()
}
private fun getIsPlaying() = player?.isPlaying == true
private fun setupColors() {