|
27 | 27 | #include <QToolBar> |
28 | 28 | #include <QStandardPaths> |
29 | 29 | #include <QStyle> |
| 30 | +#include <AmberMpris/Mpris> |
| 31 | +#include <AmberMpris/MprisPlayer> |
| 32 | +#include <AmberMpris/MprisMetaData> |
30 | 33 |
|
31 | 34 | #include "autohidewidget.h" |
32 | 35 |
|
@@ -153,6 +156,33 @@ KokoVP::KokoVP(QWidget *parent) |
153 | 156 | bottomBar->addActions(barActions); |
154 | 157 | addToolBar(Qt::BottomToolBarArea, bottomBar); |
155 | 158 |
|
| 159 | + // Mpris |
| 160 | + mpris = new Amber::MprisPlayer(this); |
| 161 | + mpris->setServiceName("org.mpris.MediaPlayer2.KokoVP"); |
| 162 | + mpris->setIdentity("KokoVP"); |
| 163 | + mpris->setSupportedUriSchemes(QStringList{"file", "http", "https"}); |
| 164 | + // TODO: Can we get the mimetypes from .desktop file ? |
| 165 | + mpris->setSupportedMimeTypes(QStringList{"audio/mpeg", "audio/x-mpeg", "audio/mp3", "audio/x-mp3", "audio/x-mpegurl", "audio/x-mpegurl", "audio/x-scpls", "audio/x-mpegurl", "audio/x-mpegurl", |
| 166 | + "audio/x-mpegurl", "audio/x-mpegurl", "audio/x-mpegurl", "audio/x-mpegurl", "audio/x-mpegurl", "audio/x-mpegurl", "audio/x-mpegurl", "audio/x-mpegurl", "audio/x-mpegurl", "audio/x-mpeg"}); |
| 167 | + mpris->setPlaybackStatus(Amber::Mpris::PlaybackStatus::Stopped); |
| 168 | + connect(player, &PlayerController::playbackChanged, mpris, [this](){mpris->setPlaybackStatus( |
| 169 | + player->isPlaying() ? Amber::Mpris::PlaybackStatus::Playing : Amber::Mpris::PlaybackStatus::Paused);}); |
| 170 | + connect(player, &PlayerController::fileMetaUpdated, mpris, [this](QString label, double duration){mpris->metaData()->setTitle(label); mpris->metaData()->setDuration(duration);}); |
| 171 | + connect(mpris, &Amber::MprisPlayer::playPauseRequested, player, &PlayerController::togglePlayback); |
| 172 | + connect(mpris, &Amber::MprisPlayer::stopRequested, player, &PlayerController::stop); |
| 173 | + connect(mpris, &Amber::MprisPlayer::seekRequested, player, &PlayerController::seekRelative); |
| 174 | + connect(mpris, &Amber::MprisPlayer::nextRequested, playlist, &Playlist::next); |
| 175 | + connect(mpris, &Amber::MprisPlayer::previousRequested, playlist, &Playlist::prev); |
| 176 | + // connect(mpris, &Amber::MprisPlayer::volumeRequested, player->prop("volume"), &PropertyObserver::set); Necessary ? How does it integrate with system volume? |
| 177 | + connect(mpris, &Amber::MprisPlayer::fullscreenRequested, this, &KokoVP::toggleFullscreen); |
| 178 | + mpris->setCanControl(true); |
| 179 | + mpris->setCanPlay(true); |
| 180 | + mpris->setCanPause(true); |
| 181 | + mpris->setCanSeek(true); |
| 182 | + mpris->setCanGoNext(true); |
| 183 | + mpris->setCanGoPrevious(true); |
| 184 | + mpris->setCanSetFullscreen(true); |
| 185 | + |
156 | 186 | // CONFIGURATION |
157 | 187 | readConfig(); |
158 | 188 | } |
@@ -529,6 +559,8 @@ void KokoVP::handleEOF(bool wasStopped) |
529 | 559 |
|
530 | 560 | if (!wasStopped && Config::i().get("play_mode/next_on_eof", true).toBool()) |
531 | 561 | playlist->next(); |
| 562 | + else |
| 563 | + mpris->setPlaybackStatus(Amber::Mpris::PlaybackStatus::Stopped); |
532 | 564 | } |
533 | 565 |
|
534 | 566 | void KokoVP::callPropEditor(QAction *callEditorAction) |
|
0 commit comments