mpris mostly works, still need to init the state though
This commit is contained in:
@@ -60,10 +60,20 @@ MediaControlWidget::MediaControlWidget()
|
||||
this->seekBar.add_css_class("control-center-seek-bar");
|
||||
|
||||
this->seekBar.signal_value_changed().connect([this]() {
|
||||
if (this->suppressSeekSignal || this->totalLengthUs <= 0) {
|
||||
return;
|
||||
}
|
||||
double fraction = this->seekBar.get_value() / 100.0;
|
||||
int64_t new_position_us =
|
||||
static_cast<int64_t>(fraction * static_cast<double>(this->totalLengthUs));
|
||||
this->mprisController->emit_seeked(new_position_us - this->currentPositionUs); // in us
|
||||
if (new_position_us == this->currentPositionUs) {
|
||||
return;
|
||||
}
|
||||
if (!this->currentTrackId.empty()) {
|
||||
this->mprisController->set_position(this->currentTrackId, new_position_us);
|
||||
} else {
|
||||
this->mprisController->emit_seeked(new_position_us - this->currentPositionUs); // in us
|
||||
}
|
||||
this->resetSeekTimer(new_position_us);
|
||||
});
|
||||
|
||||
@@ -126,12 +136,13 @@ void MediaControlWidget::onSpotifyMprisUpdated(const MprisPlayer2Message &messag
|
||||
}
|
||||
this->artistLabel.set_text(artistText);
|
||||
this->titleLabel.set_text(message.title);
|
||||
this->currentTrackId = message.track_id;
|
||||
|
||||
if (auto texture = TextureCacheService::getInstance()->getTexture(message.artwork_url)) {
|
||||
this->backgroundImage.set_paintable(texture);
|
||||
}
|
||||
|
||||
this->setTotalLength(message.length_ms);
|
||||
this->setTotalLength(message.length_ms * 1000);
|
||||
this->setCurrentPosition(0);
|
||||
this->resetSeekTimer(0);
|
||||
}
|
||||
@@ -144,7 +155,9 @@ void MediaControlWidget::setCurrentPosition(int64_t position_us) {
|
||||
std::to_string(minutes) + ":" + (seconds < 10 ? "0" : "") + std::to_string(seconds));
|
||||
if (totalLengthUs > 0) {
|
||||
double fraction = static_cast<double>(currentPositionUs) / static_cast<double>(totalLengthUs);
|
||||
this->suppressSeekSignal = true;
|
||||
this->seekBar.set_value(fraction * 100);
|
||||
this->suppressSeekSignal = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user