Wait user to clic play btn to allow upd position on partition
This commit is contained in:
parent
7bf36f3c66
commit
e02afb3580
1 changed files with 12 additions and 6 deletions
|
|
@ -119,6 +119,9 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode
|
||||||
private val _isPlayMid = MutableStateFlow(false)
|
private val _isPlayMid = MutableStateFlow(false)
|
||||||
val isPlayMid = _isPlayMid.asStateFlow()
|
val isPlayMid = _isPlayMid.asStateFlow()
|
||||||
|
|
||||||
|
private val _canUpdPositionFromPartition = MutableStateFlow(false)
|
||||||
|
val canUpdPositionFromPartition = _canUpdPositionFromPartition.asStateFlow()
|
||||||
|
|
||||||
|
|
||||||
fun loadNewSong(newMidiFile: String) {
|
fun loadNewSong(newMidiFile: String) {
|
||||||
_mediaPlayer?.stop()
|
_mediaPlayer?.stop()
|
||||||
|
|
@ -143,6 +146,7 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode
|
||||||
}
|
}
|
||||||
|
|
||||||
fun togglePlayPause() {
|
fun togglePlayPause() {
|
||||||
|
_canUpdPositionFromPartition.value=true
|
||||||
_mediaPlayer?.let { player ->
|
_mediaPlayer?.let { player ->
|
||||||
if (_isPlay.value) {
|
if (_isPlay.value) {
|
||||||
_isPlay.value = false
|
_isPlay.value = false
|
||||||
|
|
@ -196,12 +200,14 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode
|
||||||
var currentNoteIndex by mutableStateOf(0f)
|
var currentNoteIndex by mutableStateOf(0f)
|
||||||
|
|
||||||
fun updatePositionFromPartition(index: Int, totalRow: Int) {
|
fun updatePositionFromPartition(index: Int, totalRow: Int) {
|
||||||
val duration = _duration.value
|
if(_canUpdPositionFromPartition.value) { /*upd pos part only if midi on playing*/
|
||||||
if(totalRow > 0) {
|
val duration = _duration.value
|
||||||
currentNoteIndex = index.toFloat()
|
if(totalRow > 0) {
|
||||||
val newPos = (currentNoteIndex / totalRow.toFloat()) * duration
|
currentNoteIndex = index.toFloat()
|
||||||
seekTo(newPos)
|
val newPos = (currentNoteIndex / totalRow.toFloat()) * duration
|
||||||
println("Shared:196 currentNoteIndex $currentNoteIndex, Index $index et curret = ${_currentPos.value}")
|
seekTo(newPos)
|
||||||
|
println("Shared:196 currentNoteIndex $currentNoteIndex, Index $index et curret = ${_currentPos.value}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue