close one notification to close all
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "widgets/controlCenter/mediaControl.hpp"
|
||||
|
||||
#include "helpers/string.hpp"
|
||||
#include "services/textureCache.hpp"
|
||||
|
||||
MediaControlWidget::MediaControlWidget()
|
||||
@@ -62,7 +63,7 @@ MediaControlWidget::MediaControlWidget()
|
||||
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); // in ms
|
||||
this->mprisController->emit_seeked(new_position_us - this->currentPositionUs); // in us
|
||||
this->resetSeekTimer(new_position_us);
|
||||
});
|
||||
|
||||
@@ -100,6 +101,16 @@ MediaControlWidget::MediaControlWidget()
|
||||
this->mprisController->signal_mpris_updated().connect(
|
||||
sigc::mem_fun(*this, &MediaControlWidget::onSpotifyMprisUpdated));
|
||||
|
||||
this->mprisController->signal_playback_status_changed().connect(
|
||||
[this](MprisController::PlaybackStatus status) {
|
||||
this->onRunningStateChanged(status);
|
||||
});
|
||||
|
||||
this->mprisController->signal_playback_position_changed().connect(
|
||||
[this](int64_t position_us) {
|
||||
this->setCurrentPosition(position_us);
|
||||
});
|
||||
|
||||
this->artistLabel.set_text("Artist Name");
|
||||
this->artistLabel.add_css_class("control-center-spotify-artist-label");
|
||||
this->titleLabel.set_text("Song Title");
|
||||
@@ -109,7 +120,11 @@ MediaControlWidget::MediaControlWidget()
|
||||
}
|
||||
|
||||
void MediaControlWidget::onSpotifyMprisUpdated(const MprisPlayer2Message &message) {
|
||||
this->artistLabel.set_text(message.artist);
|
||||
std::string artistText = "Unknown Artist";
|
||||
if (!message.artist.empty()) {
|
||||
artistText = StringHelper::trimToSize(message.artist[0], 30);
|
||||
}
|
||||
this->artistLabel.set_text(artistText);
|
||||
this->titleLabel.set_text(message.title);
|
||||
|
||||
if (auto texture = TextureCacheService::getInstance()->getTexture(message.artwork_url)) {
|
||||
@@ -164,4 +179,39 @@ bool MediaControlWidget::onSeekTick() {
|
||||
}
|
||||
setCurrentPosition(nextPosition);
|
||||
return true;
|
||||
}
|
||||
|
||||
void MediaControlWidget::onRunningStateChanged(MprisController::PlaybackStatus status) {
|
||||
switch (status) {
|
||||
case MprisController::PlaybackStatus::Playing:
|
||||
this->onPlay();
|
||||
break;
|
||||
case MprisController::PlaybackStatus::Paused:
|
||||
this->onPause();
|
||||
break;
|
||||
case MprisController::PlaybackStatus::Stopped:
|
||||
this->onStop();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MediaControlWidget::onPlay() {
|
||||
this->playPauseButton.set_label("\u23F8"); // Pause symbol
|
||||
// strart seek timer if not already running
|
||||
this->resetSeekTimer(currentPositionUs);
|
||||
}
|
||||
|
||||
void MediaControlWidget::onPause() {
|
||||
this->playPauseButton.set_label("\u23EF"); // Play symbol
|
||||
if (seekTimerConnection.connected()) {
|
||||
seekTimerConnection.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
void MediaControlWidget::onStop() {
|
||||
this->playPauseButton.set_label("\u23EF"); // Play symbol
|
||||
if (seekTimerConnection.connected()) {
|
||||
seekTimerConnection.disconnect();
|
||||
}
|
||||
this->setCurrentPosition(0);
|
||||
}
|
||||
Reference in New Issue
Block a user