Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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})
Expand Down
33 changes: 33 additions & 0 deletions kokovp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#include <QToolBar>
#include <QStandardPaths>
#include <QStyle>
#include <AmberMpris/Mpris>
#include <AmberMpris/MprisPlayer>
#include <AmberMpris/MprisMetaData>

#include "autohidewidget.h"

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions kokovp.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class TracksMenu;
class AutohideWidget;
class FileSettingsHash;
class QTableView;
namespace Amber { class MprisPlayer; }

using QActionMap = QMap<QString, QAction*>;

Expand Down Expand Up @@ -96,6 +97,8 @@ class KokoVP : public QMainWindow

QActionMap p_actionsMap;

Amber::MprisPlayer *mpris;

static KokoVP *inst;
};

Expand Down
3 changes: 3 additions & 0 deletions playercontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "playerwidget.h"
#include "helper.h"


PlayerController::PlayerController(PlayerWidget *parent)
: QObject{parent}
{
Expand Down Expand Up @@ -108,6 +109,7 @@ void PlayerController::stop()
void PlayerController::togglePlayback()
{
p->setProp("pause", isPlaying());
emit playbackChanged();
}

void PlayerController::seekAbsolute(double s)
Expand Down Expand Up @@ -196,4 +198,5 @@ void PlayerController::handleFileLoad()

emit tracksUpdated();
emit fileMetaUpdated(p->getProp("media-title").toString(), prop("duration")->get().toDouble());
emit playbackChanged();
}
2 changes: 2 additions & 0 deletions playercontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <QDir>
#include <QUrl>


class PlayerWidget;
class PropertyObserver;

Expand Down Expand Up @@ -81,6 +82,7 @@ class PlayerController : public QObject
const QList<Track> &tracks() const { return p_tracks; }

signals:
void playbackChanged();
void tracksUpdated();
void fileMetaUpdated(QString label, double duration);
void endFile(bool wasStopped);
Expand Down
1 change: 1 addition & 0 deletions singleinstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
#include "singleinstance.h"

#include <QDebug>
#include <QLocalSocket>
#include <QLocalServer>

Expand Down