media widget fix
This commit is contained in:
@@ -71,10 +71,19 @@ MediaControlWidget::MediaControlWidget()
|
||||
}
|
||||
if (!this->currentTrackId.empty()) {
|
||||
this->mprisController->set_position(this->currentTrackId, new_position_us);
|
||||
} else {
|
||||
if (this->playbackStatus != MprisController::PlaybackStatus::Playing) {
|
||||
this->schedulePauseAfterSeek();
|
||||
}
|
||||
} else if (this->playbackStatus == MprisController::PlaybackStatus::Playing) {
|
||||
this->mprisController->emit_seeked(new_position_us - this->currentPositionUs); // in us
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
if (this->playbackStatus == MprisController::PlaybackStatus::Playing) {
|
||||
this->resetSeekTimer(new_position_us);
|
||||
} else {
|
||||
this->setCurrentPosition(new_position_us);
|
||||
}
|
||||
this->resetSeekTimer(new_position_us);
|
||||
});
|
||||
|
||||
this->bottomContainer.set_orientation(Gtk::Orientation::HORIZONTAL);
|
||||
@@ -136,15 +145,25 @@ void MediaControlWidget::onSpotifyMprisUpdated(const MprisPlayer2Message &messag
|
||||
}
|
||||
this->artistLabel.set_text(artistText);
|
||||
this->titleLabel.set_text(message.title);
|
||||
const bool trackChanged = !this->currentTrackId.empty() && this->currentTrackId != message.track_id;
|
||||
this->currentTrackId = message.track_id;
|
||||
|
||||
if (trackChanged) {
|
||||
this->currentPositionUs = 0;
|
||||
}
|
||||
|
||||
if (auto texture = TextureCacheService::getInstance()->getTexture(message.artwork_url)) {
|
||||
this->backgroundImage.set_paintable(texture);
|
||||
}
|
||||
|
||||
this->setTotalLength(message.length_ms * 1000);
|
||||
this->setCurrentPosition(0);
|
||||
this->resetSeekTimer(0);
|
||||
this->setCurrentPosition(this->currentPositionUs);
|
||||
|
||||
if (this->playbackStatus == MprisController::PlaybackStatus::Playing) {
|
||||
this->resetSeekTimer(this->currentPositionUs);
|
||||
} else if (seekTimerConnection.connected()) {
|
||||
seekTimerConnection.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
void MediaControlWidget::setCurrentPosition(int64_t position_us) {
|
||||
@@ -181,6 +200,14 @@ void MediaControlWidget::resetSeekTimer(int64_t start_position_us) {
|
||||
1000);
|
||||
}
|
||||
|
||||
void MediaControlWidget::schedulePauseAfterSeek() {
|
||||
Glib::signal_timeout().connect_once([this]() {
|
||||
if (this->playbackStatus != MprisController::PlaybackStatus::Playing) {
|
||||
this->mprisController->pause();
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
|
||||
bool MediaControlWidget::onSeekTick() {
|
||||
if (totalLengthUs <= 0) {
|
||||
return true;
|
||||
@@ -195,6 +222,7 @@ bool MediaControlWidget::onSeekTick() {
|
||||
}
|
||||
|
||||
void MediaControlWidget::onRunningStateChanged(MprisController::PlaybackStatus status) {
|
||||
this->playbackStatus = status;
|
||||
switch (status) {
|
||||
case MprisController::PlaybackStatus::Playing:
|
||||
this->onPlay();
|
||||
@@ -215,14 +243,14 @@ void MediaControlWidget::onPlay() {
|
||||
}
|
||||
|
||||
void MediaControlWidget::onPause() {
|
||||
this->playPauseButton.set_label("\u23EF"); // Play symbol
|
||||
this->playPauseButton.set_label("\u23F5"); // Play symbol
|
||||
if (seekTimerConnection.connected()) {
|
||||
seekTimerConnection.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
void MediaControlWidget::onStop() {
|
||||
this->playPauseButton.set_label("\u23EF"); // Play symbol
|
||||
this->playPauseButton.set_label("\u23F9"); // stop symbol
|
||||
if (seekTimerConnection.connected()) {
|
||||
seekTimerConnection.disconnect();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user