Fix preview seek times in cut mode

This commit is contained in:
Max Jakobitsch 2025-02-24 20:11:16 +01:00
parent 2cd41421c2
commit d90d8193e7

View file

@ -56,6 +56,7 @@ import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import java.util.* import java.util.*
import kotlin.math.max
class CutVideoBottomSheetDialog(private val _item: DownloadItem? = null, private val urls : String? = null, private var chapters: List<ChapterItem>? = null, private val listener: VideoCutListener? = null) : BottomSheetDialogFragment() { class CutVideoBottomSheetDialog(private val _item: DownloadItem? = null, private val urls : String? = null, private var chapters: List<ChapterItem>? = null, private val listener: VideoCutListener? = null) : BottomSheetDialogFragment() {
@ -453,10 +454,7 @@ class CutVideoBottomSheetDialog(private val _item: DownloadItem? = null, private
val startTimestampString = startTimestamp.toStringTimeStamp() val startTimestampString = startTimestamp.toStringTimeStamp()
val endTimestampString = endTimestamp.toStringTimeStamp() val endTimestampString = endTimestamp.toStringTimeStamp()
var draggedFromBeginning = true val draggedFromBeginning = rangeSlider.focusedThumbIndex != 1
if (toTextInput.text.toString() != endTimestampString){
draggedFromBeginning = false
}
fromTextInput.setTextAndRecalculateWidth(startTimestampString) fromTextInput.setTextAndRecalculateWidth(startTimestampString)
toTextInput.setTextAndRecalculateWidth(endTimestampString) toTextInput.setTextAndRecalculateWidth(endTimestampString)
@ -464,14 +462,11 @@ class CutVideoBottomSheetDialog(private val _item: DownloadItem? = null, private
okBtn.isEnabled = values[0] != 0F || values[1] != (itemDurationTimestamp / 1000).toFloat() okBtn.isEnabled = values[0] != 0F || values[1] != (itemDurationTimestamp / 1000).toFloat()
val startpos = startTimestamp * 1000
try { try {
if (draggedFromBeginning){ if (draggedFromBeginning){
player.seekTo(startpos) player.seekTo(startTimestamp)
}else{ }else{
var endpos = (endTimestamp * 1000) - 1500 player.seekTo(max(startTimestamp, endTimestamp - 1500))
if (endpos < (startTimestamp * 1000)) endpos = startpos
player.seekTo(endpos)
} }
player.play() player.play()
}catch (ignored: Exception) {} }catch (ignored: Exception) {}