diff --git a/CMakeLists.txt b/CMakeLists.txt index e05c09f..f7c2870 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,7 @@ find_package(QT NAMES Qt6) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets LinguistTools OpenGLWidgets Network Xml) find_package(PkgConfig REQUIRED) pkg_check_modules(mpv REQUIRED mpv) +pkg_check_modules(AmberMpris REQUIRED ambermpris6) # Libraries set(LIBRARIES @@ -30,6 +31,7 @@ set(LIBRARIES Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::Xml ${mpv_LIBRARIES} + ${AmberMpris_LIBRARIES} ) set(TS_FILES KokoVP_ru_RU.ts) @@ -126,7 +128,7 @@ qt_wrap_ui(FORMS ${UI}) qt_create_translation(QM_FILES ${TS_FILES} ${MAIN_SRC}) qt_add_resources(QRC_CPP icons.qrc) -include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}) +include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} "/usr/include/AmberMpris") add_executable(kokovp ${MOC_FILES} ${FORMS} ${MAIN_SRC} ${QRC_CPP}) target_link_libraries(kokovp ${LIBRARIES}) diff --git a/kokovp.cpp b/kokovp.cpp index 19e79e0..62fca11 100644 --- a/kokovp.cpp +++ b/kokovp.cpp @@ -27,6 +27,9 @@ #include #include #include +#include +#include +#include #include "autohidewidget.h" @@ -153,6 +156,34 @@ KokoVP::KokoVP(QWidget *parent) bottomBar->addActions(barActions); addToolBar(Qt::BottomToolBarArea, bottomBar); + // Mpris + mpris = new Amber::MprisPlayer(this); + mpris->setServiceName("org.mpris.MediaPlayer2.KokoVP"); + mpris->setIdentity("KokoVP"); + mpris->setSupportedUriSchemes(QStringList{"file", "http", "https"}); + // TODO: Can we get the mimetypes from .desktop file ? + 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", + "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"}); + mpris->setPlaybackStatus(Amber::Mpris::PlaybackStatus::Stopped); + connect(player, &PlayerController::playbackChanged, mpris, [this](){mpris->setPlaybackStatus( + player->isPlaying() ? Amber::Mpris::PlaybackStatus::Playing : Amber::Mpris::PlaybackStatus::Paused);}); + connect(player, &PlayerController::fileMetaUpdated, mpris, [this](QString label, double duration){mpris->metaData()->setTitle(label); mpris->metaData()->setDuration(duration);}); + connect(mpris, &Amber::MprisPlayer::playRequested, player, [this](){if (!player->isPlaying()) { player->togglePlayback(); tryPlayCurrent(); }}); + connect(mpris, &Amber::MprisPlayer::playPauseRequested, player, &PlayerController::togglePlayback); + connect(mpris, &Amber::MprisPlayer::stopRequested, player, &PlayerController::stop); + connect(mpris, &Amber::MprisPlayer::seekRequested, player, &PlayerController::seekRelative); + connect(mpris, &Amber::MprisPlayer::nextRequested, playlist, &Playlist::next); + connect(mpris, &Amber::MprisPlayer::previousRequested, playlist, &Playlist::prev); + // connect(mpris, &Amber::MprisPlayer::volumeRequested, player->prop("volume"), &PropertyObserver::set); Necessary ? How does it integrate with system volume? + connect(mpris, &Amber::MprisPlayer::fullscreenRequested, this, &KokoVP::toggleFullscreen); + mpris->setCanControl(true); + mpris->setCanPlay(true); + mpris->setCanPause(true); + mpris->setCanSeek(true); + mpris->setCanGoNext(true); + mpris->setCanGoPrevious(true); + mpris->setCanSetFullscreen(true); + // CONFIGURATION readConfig(); } @@ -524,6 +555,8 @@ void KokoVP::handleEOF(bool wasStopped) if (!wasStopped && Config::i().get("play_mode/next_on_eof", true).toBool()) playlist->next(); + else + mpris->setPlaybackStatus(Amber::Mpris::PlaybackStatus::Stopped); } void KokoVP::callPropEditor(QAction *callEditorAction) diff --git a/kokovp.h b/kokovp.h index 8bfc6d0..c96c8b3 100644 --- a/kokovp.h +++ b/kokovp.h @@ -28,6 +28,7 @@ class TracksMenu; class AutohideWidget; class FileSettingsHash; class QTableView; +namespace Amber { class MprisPlayer; } using QActionMap = QMap; @@ -96,6 +97,8 @@ class KokoVP : public QMainWindow QActionMap p_actionsMap; + Amber::MprisPlayer *mpris; + static KokoVP *inst; }; diff --git a/playercontroller.cpp b/playercontroller.cpp index 41beb54..b0f86c5 100644 --- a/playercontroller.cpp +++ b/playercontroller.cpp @@ -19,6 +19,7 @@ #include "playerwidget.h" #include "helper.h" + PlayerController::PlayerController(PlayerWidget *parent) : QObject{parent} { @@ -108,6 +109,7 @@ void PlayerController::stop() void PlayerController::togglePlayback() { p->setProp("pause", isPlaying()); + emit playbackChanged(); } void PlayerController::seekAbsolute(double s) @@ -196,4 +198,5 @@ void PlayerController::handleFileLoad() emit tracksUpdated(); emit fileMetaUpdated(p->getProp("media-title").toString(), prop("duration")->get().toDouble()); + emit playbackChanged(); } diff --git a/playercontroller.h b/playercontroller.h index e72574c..76b2b42 100644 --- a/playercontroller.h +++ b/playercontroller.h @@ -21,6 +21,7 @@ #include #include + class PlayerWidget; class PropertyObserver; @@ -81,6 +82,7 @@ class PlayerController : public QObject const QList &tracks() const { return p_tracks; } signals: + void playbackChanged(); void tracksUpdated(); void fileMetaUpdated(QString label, double duration); void endFile(bool wasStopped); diff --git a/singleinstance.cpp b/singleinstance.cpp index a3d88f3..ace2cdc 100644 --- a/singleinstance.cpp +++ b/singleinstance.cpp @@ -16,6 +16,7 @@ */ #include "singleinstance.h" +#include #include #include