mirror of
https://github.com/SimpleMobileTools/Simple-Voice-Recorder.git
synced 2025-06-05 21:59:31 +02:00
add fast forwarding and rewinding
This commit is contained in:
@ -22,6 +22,8 @@ import java.util.*
|
|||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) {
|
class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) {
|
||||||
|
private val FAST_FORWARD_SKIP_MS = 10000
|
||||||
|
|
||||||
private var player: MediaPlayer? = null
|
private var player: MediaPlayer? = null
|
||||||
private var progressTimer = Timer()
|
private var progressTimer = Timer()
|
||||||
|
|
||||||
@ -58,6 +60,14 @@ class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPager
|
|||||||
play_pause_btn.setOnClickListener {
|
play_pause_btn.setOnClickListener {
|
||||||
togglePlayPause()
|
togglePlayPause()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
player_progress_current.setOnClickListener {
|
||||||
|
skip(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
player_progress_max.setOnClickListener {
|
||||||
|
skip(true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("InlinedApi")
|
@SuppressLint("InlinedApi")
|
||||||
@ -201,6 +211,17 @@ class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPager
|
|||||||
play_pause_btn.setImageDrawable(drawable)
|
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 getIsPlaying() = player?.isPlaying == true
|
||||||
|
|
||||||
private fun setupColors() {
|
private fun setupColors() {
|
||||||
|
Reference in New Issue
Block a user