Wait user to clic play btn to allow upd position on partition

This commit is contained in:
hasinarak3@gmail.com 2026-02-17 10:58:03 +03:00
parent 7bf36f3c66
commit e02afb3580

View file

@ -119,6 +119,9 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode
private val _isPlayMid = MutableStateFlow(false)
val isPlayMid = _isPlayMid.asStateFlow()
private val _canUpdPositionFromPartition = MutableStateFlow(false)
val canUpdPositionFromPartition = _canUpdPositionFromPartition.asStateFlow()
fun loadNewSong(newMidiFile: String) {
_mediaPlayer?.stop()
@ -143,6 +146,7 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode
}
fun togglePlayPause() {
_canUpdPositionFromPartition.value=true
_mediaPlayer?.let { player ->
if (_isPlay.value) {
_isPlay.value = false
@ -196,12 +200,14 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode
var currentNoteIndex by mutableStateOf(0f)
fun updatePositionFromPartition(index: Int, totalRow: Int) {
val duration = _duration.value
if(totalRow > 0) {
currentNoteIndex = index.toFloat()
val newPos = (currentNoteIndex / totalRow.toFloat()) * duration
seekTo(newPos)
println("Shared:196 currentNoteIndex $currentNoteIndex, Index $index et curret = ${_currentPos.value}")
if(_canUpdPositionFromPartition.value) { /*upd pos part only if midi on playing*/
val duration = _duration.value
if(totalRow > 0) {
currentNoteIndex = index.toFloat()
val newPos = (currentNoteIndex / totalRow.toFloat()) * duration
seekTo(newPos)
println("Shared:196 currentNoteIndex $currentNoteIndex, Index $index et curret = ${_currentPos.value}")
}
}
}