Skip to content

Commit c52ccc7

Browse files
committed
Initial mpris support.
Not feature complete yet.
1 parent bc3229c commit c52ccc7

File tree

5 files changed

+43
-1
lines changed

5 files changed

+43
-1
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ find_package(QT NAMES Qt6)
2121
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets LinguistTools OpenGLWidgets Network Xml)
2222
find_package(PkgConfig REQUIRED)
2323
pkg_check_modules(mpv REQUIRED mpv)
24+
pkg_check_modules(AmberMpris REQUIRED ambermpris6)
2425

2526
# Libraries
2627
set(LIBRARIES
@@ -30,6 +31,7 @@ set(LIBRARIES
3031
Qt${QT_VERSION_MAJOR}::Network
3132
Qt${QT_VERSION_MAJOR}::Xml
3233
${mpv_LIBRARIES}
34+
${AmberMpris_LIBRARIES}
3335
)
3436

3537
set(TS_FILES KokoVP_ru_RU.ts)
@@ -126,7 +128,7 @@ qt_wrap_ui(FORMS ${UI})
126128
qt_create_translation(QM_FILES ${TS_FILES} ${MAIN_SRC})
127129
qt_add_resources(QRC_CPP icons.qrc)
128130

129-
include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
131+
include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} "/usr/include/AmberMpris")
130132

131133
add_executable(kokovp ${MOC_FILES} ${FORMS} ${MAIN_SRC} ${QRC_CPP})
132134
target_link_libraries(kokovp ${LIBRARIES})

kokovp.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
#include <QToolBar>
2828
#include <QStandardPaths>
2929
#include <QStyle>
30+
#include <AmberMpris/Mpris>
31+
#include <AmberMpris/MprisPlayer>
32+
#include <AmberMpris/MprisMetaData>
3033

3134
#include "autohidewidget.h"
3235

@@ -153,6 +156,33 @@ KokoVP::KokoVP(QWidget *parent)
153156
bottomBar->addActions(barActions);
154157
addToolBar(Qt::BottomToolBarArea, bottomBar);
155158

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+
156186
// CONFIGURATION
157187
readConfig();
158188
}
@@ -529,6 +559,8 @@ void KokoVP::handleEOF(bool wasStopped)
529559

530560
if (!wasStopped && Config::i().get("play_mode/next_on_eof", true).toBool())
531561
playlist->next();
562+
else
563+
mpris->setPlaybackStatus(Amber::Mpris::PlaybackStatus::Stopped);
532564
}
533565

534566
void KokoVP::callPropEditor(QAction *callEditorAction)

kokovp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class TracksMenu;
2828
class AutohideWidget;
2929
class FileSettingsHash;
3030
class QTableView;
31+
namespace Amber { class MprisPlayer; }
3132

3233
using QActionMap = QMap<QString, QAction*>;
3334

@@ -96,6 +97,8 @@ class KokoVP : public QMainWindow
9697

9798
QActionMap p_actionsMap;
9899

100+
Amber::MprisPlayer *mpris;
101+
99102
static KokoVP *inst;
100103
};
101104

playercontroller.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "playerwidget.h"
2121
#include "helper.h"
2222

23+
2324
const QString PlayerController::volumeLevelConfigKey = QString("audio/volume_level");
2425
const QString PlayerController::audioMutedConfigKey = QString("audio/muted");
2526

@@ -113,6 +114,7 @@ void PlayerController::stop()
113114
void PlayerController::togglePlayback()
114115
{
115116
p->setProp("pause", isPlaying());
117+
emit playbackChanged();
116118
}
117119

118120
void PlayerController::seekAbsolute(double s)
@@ -201,4 +203,5 @@ void PlayerController::handleFileLoad()
201203

202204
emit tracksUpdated();
203205
emit fileMetaUpdated(p->getProp("media-title").toString(), prop("duration")->get().toDouble());
206+
emit playbackChanged();
204207
}

playercontroller.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <QDir>
2222
#include <QUrl>
2323

24+
2425
class PlayerWidget;
2526
class PropertyObserver;
2627

@@ -84,6 +85,7 @@ class PlayerController : public QObject
8485
const QList<Track> &tracks() const { return p_tracks; }
8586

8687
signals:
88+
void playbackChanged();
8789
void tracksUpdated();
8890
void fileMetaUpdated(QString label, double duration);
8991
void endFile(bool wasStopped);

0 commit comments

Comments
 (0)