Skip to content
Open
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
5 changes: 5 additions & 0 deletions src/libdmusic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,10 @@ target_link_libraries(${CMD_NAME} Qt6::Core Qt6::Multimedia Qt6::DBus Qt6::Sql Q

# qt5_use_modules(${CMD_NAME} )

# Windows SMTC support
if(WIN32 AND NOT MSVC)
target_link_libraries(${CMD_NAME} runtimeobject ole32 user32 propsys shell32)
endif()

include(GNUInstallDirs)
install(TARGETS ${CMD_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR})
116 changes: 114 additions & 2 deletions src/libdmusic/player/playerengine.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Copyright (C) 2020 ~ 2020 Deepin Technology Co., Ltd.
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand All @@ -12,10 +11,16 @@
#include <QFileInfo>
#include <QRandomGenerator>
#include <QPropertyAnimation>
#include <QIcon>

Check warning on line 14 in src/libdmusic/player/playerengine.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QIcon> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDBusConnection>

Check warning on line 15 in src/libdmusic/player/playerengine.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDBusConnection> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#ifdef Q_OS_LINUX
#include <MprisPlayer>

Check warning on line 18 in src/libdmusic/player/playerengine.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <MprisPlayer> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#endif

#ifdef Q_OS_WIN
#include "winsmtc.h"
#endif

#include "qtplayer.h"
#include "vlcplayer.h"
Expand Down Expand Up @@ -60,7 +65,14 @@
int m_pendingManualNavigation = 0;
bool m_keepManualNavigation = false;
PlayerBase *m_player = nullptr;
#ifdef Q_OS_LINUX
MprisPlayer *m_mprisPlayer = nullptr;
#else
void *m_mprisPlayer = nullptr;
#endif
#ifdef Q_OS_WIN
WinSMTC *m_winSmtc = nullptr;
#endif
QString m_playlistHash;
DmGlobal::PlaybackMode m_playbackMode = DmGlobal::RepeatNull;
int m_playingCount = 0;
Expand Down Expand Up @@ -190,11 +202,20 @@
PlayerEngine::~PlayerEngine()
{
qCDebug(dmMusic) << "Destroying PlayerEngine";
#ifdef Q_OS_LINUX
if (m_data->m_mprisPlayer) {
qCDebug(dmMusic) << "Destroying MprisPlayer";
delete m_data->m_mprisPlayer;
m_data->m_mprisPlayer = nullptr;
}
#endif
#ifdef Q_OS_WIN
if (m_data->m_winSmtc) {
m_data->m_winSmtc->shutdown();
delete m_data->m_winSmtc;
m_data->m_winSmtc = nullptr;
}
#endif
}

double PlayerEngine::fadeInOutFactor() const
Expand All @@ -216,6 +237,7 @@
}
}

#ifdef Q_OS_LINUX
void PlayerEngine::setMprisPlayer(const QString &serviceName, const QString &desktopEntry, const QString &identity)
{
qCDebug(dmMusic) << "Initializing MprisPlayer with service:" << serviceName;
Expand Down Expand Up @@ -313,6 +335,75 @@
connect(m_data->m_mprisPlayer, &MprisPlayer::raiseRequested, this, &PlayerEngine::raiseRequested);
qCDebug(dmMusic) << "MprisPlayer initialized";
}
#endif

#ifdef Q_OS_WIN
void PlayerEngine::setWinSMTC(void *hwnd)
{
if (!hwnd) return;

m_data->m_winSmtc = new WinSMTC(this);

if (!m_data->m_winSmtc->initialize(static_cast<HWND>(hwnd))) {
qWarning() << "WinSMTC: Failed to initialize";
delete m_data->m_winSmtc;
m_data->m_winSmtc = nullptr;
return;
}

connect(m_data->m_winSmtc, &WinSMTC::playRequested, this, [this]() {
if (playbackStatus() == DmGlobal::Paused) {
resume();
} else if (playbackStatus() != DmGlobal::Playing) {
if (isEmpty()) {
Q_EMIT playPlaylistRequested("all");
} else {
if (!getMediaMeta().localPath.isEmpty() && !getMediaMeta().hash.isEmpty()) {
play();
} else {
playNextMeta(false);
}
}
} else {
pauseNow();
}
});

connect(m_data->m_winSmtc, &WinSMTC::pauseRequested, this, &PlayerEngine::pauseNow);

connect(m_data->m_winSmtc, &WinSMTC::stopRequested, this, &PlayerEngine::stop);

connect(m_data->m_winSmtc, &WinSMTC::nextRequested, this, [this]() {
playNextMeta(false);
});

connect(m_data->m_winSmtc, &WinSMTC::previousRequested, this, &PlayerEngine::playPreMeta);

connect(this, &PlayerEngine::playbackStatusChanged, this, [this](DmGlobal::PlaybackStatus status) {
if (!m_data->m_winSmtc) return;
switch (status) {
case DmGlobal::Playing:
m_data->m_winSmtc->updatePlaybackStatus(1);
break;
case DmGlobal::Paused:
m_data->m_winSmtc->updatePlaybackStatus(2);
break;
default:
m_data->m_winSmtc->updatePlaybackStatus(0);
break;
}
});

m_data->m_winSmtc->setControlsEnabled(true, true, true,
hasNextPlayableMeta(getMediaMeta().hash),
hasPreviousPlayableMeta(getMediaMeta().hash));

MediaMeta currentMeta = getMediaMeta();
if (!currentMeta.hash.isEmpty()) {
resetDBusMpris(currentMeta);
}
}
#endif

void PlayerEngine::setMediaMeta(const QString &metaHash)
{
Expand Down Expand Up @@ -899,6 +990,7 @@

void PlayerEngine::resetDBusMpris(const DMusic::MediaMeta &meta)
{
#ifdef Q_OS_LINUX
qCDebug(dmMusic) << "Resetting DBus Mpris with meta:" << meta.title;
QVariantMap metadata;
metadata.insert(Mpris::metadataToString(Mpris::Title), meta.title);
Expand All @@ -920,6 +1012,26 @@
metadata.insert(Mpris::metadataToString(Mpris::ArtUrl), str);
m_data->m_mprisPlayer->setMetadata(metadata);
qCDebug(dmMusic) << "DBus Mpris reset with meta:" << meta.title;
#endif
#ifdef Q_OS_WIN
if (m_data->m_winSmtc) {
QString artPath = DmGlobal::cachePath() + "/images/" + meta.hash + ".jpg";
QFileInfo artInfo(artPath);
if (!artInfo.exists()) {
artPath = DmGlobal::cachePath() + "/images/" + "default_cover_max.jpg";
artInfo.setFile(artPath);
if (!artInfo.exists()) {
QIcon icon = QIcon::fromTheme("cover_max");
icon.pixmap(QSize(50, 50)).save(artPath);
}
}
m_data->m_winSmtc->updateMetadata(meta.title, meta.artist, meta.album,
meta.length, artPath);
m_data->m_winSmtc->setControlsEnabled(true, true, true,
hasNextPlayableMeta(meta.hash),
hasPreviousPlayableMeta(meta.hash));
}
#endif
}

void PlayerEngine::playNextMeta(bool isAuto, bool playFlag)
Expand Down
8 changes: 6 additions & 2 deletions src/libdmusic/player/playerengine.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Copyright (C) 2020 ~ 2020 Deepin Technology Co., Ltd.
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand All @@ -22,7 +21,12 @@ class PlayerEngine : public QObject

double fadeInOutFactor() const;
void setFadeInOut(bool flag);
#ifdef Q_OS_LINUX
void setMprisPlayer(const QString &serviceName, const QString &desktopEntry, const QString &identity);
#endif
#ifdef Q_OS_WIN
void setWinSMTC(void *hwnd);
#endif
void setMediaMeta(const QString &metaHash);
void setMediaMeta(const DMusic::MediaMeta &metaList);
QStringList supportedSuffixList()const;
Expand Down
Loading
Loading