Skip to content

Commit 8721bf6

Browse files
Warchamp7Lain-B
authored andcommitted
UI: Update media source time labels while seeking
1 parent c54f437 commit 8721bf6

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

UI/media-controls.cpp

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ void MediaControls::MediaSliderReleased()
160160
obs_source_media_set_time(source, GetSliderTime(seek));
161161
}
162162

163+
UpdateLabels(seek);
163164
seek = lastSeek = -1;
164165
}
165166

@@ -179,6 +180,7 @@ void MediaControls::MediaSliderMoved(int val)
179180
{
180181
if (seekTimer.isActive()) {
181182
seek = val;
183+
UpdateLabels(seek);
182184
}
183185
}
184186

@@ -358,16 +360,7 @@ void MediaControls::SetSliderPosition()
358360
sliderPosition = 0.0f;
359361

360362
ui->slider->setValue((int)sliderPosition);
361-
362-
ui->timerLabel->setText(FormatSeconds((int)(time / 1000.0f)));
363-
364-
if (!countDownTimer)
365-
ui->durationLabel->setText(
366-
FormatSeconds((int)(duration / 1000.0f)));
367-
else
368-
ui->durationLabel->setText(
369-
QString("-") +
370-
FormatSeconds((int)((duration - time) / 1000.0f)));
363+
UpdateLabels((int)sliderPosition);
371364
}
372365

373366
QString MediaControls::FormatSeconds(int totalSeconds)
@@ -535,3 +528,26 @@ void MediaControls::UpdateSlideCounter()
535528
ui->durationLabel->setText("-");
536529
}
537530
}
531+
532+
void MediaControls::UpdateLabels(int val)
533+
{
534+
OBSSource source = OBSGetStrongRef(weakSource);
535+
if (!source) {
536+
return;
537+
}
538+
539+
float duration = (float)obs_source_media_get_duration(source);
540+
float percent = (float)val / (float)ui->slider->maximum();
541+
542+
float time = percent * duration;
543+
544+
ui->timerLabel->setText(FormatSeconds((int)(time / 1000.0f)));
545+
546+
if (!countDownTimer)
547+
ui->durationLabel->setText(
548+
FormatSeconds((int)(duration / 1000.0f)));
549+
else
550+
ui->durationLabel->setText(
551+
QString("-") +
552+
FormatSeconds((int)((duration - time) / 1000.0f)));
553+
}

UI/media-controls.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ private slots:
6464
void MoveSliderBackwards(int seconds = 5);
6565

6666
void UpdateSlideCounter();
67+
void UpdateLabels(int val);
6768

6869
public slots:
6970
void PlayMedia();

0 commit comments

Comments
 (0)