From ae3e123f8f76d9bb104ab95b9e6a942cbb1631d0 Mon Sep 17 00:00:00 2001 From: Piyush Aggarwal Date: Tue, 13 Jul 2021 18:59:30 +0530 Subject: [PATCH] add NOT WORKING albumart support --- plugins/mpriscontrol/CMakeLists.txt | 2 +- .../mpriscontrol/mpriscontrolplugin-win.cpp | 80 +++++++++++++++---- 2 files changed, 67 insertions(+), 15 deletions(-) diff --git a/plugins/mpriscontrol/CMakeLists.txt b/plugins/mpriscontrol/CMakeLists.txt index f5ac0e44..cf2fc814 100644 --- a/plugins/mpriscontrol/CMakeLists.txt +++ b/plugins/mpriscontrol/CMakeLists.txt @@ -30,7 +30,7 @@ ecm_qt_declare_logging_category( kdeconnect_add_plugin(kdeconnect_mpriscontrol SOURCES ${kdeconnect_mpriscontrol_SRCS} ${debug_file_SRCS}) if(WIN32) - target_link_libraries(kdeconnect_mpriscontrol kdeconnectcore windowsapp) + target_link_libraries(kdeconnect_mpriscontrol kdeconnectcore windowsapp Qt5::Gui) target_compile_features(kdeconnect_mpriscontrol PUBLIC cxx_std_17) else() target_link_libraries(kdeconnect_mpriscontrol Qt5::DBus kdeconnectcore) diff --git a/plugins/mpriscontrol/mpriscontrolplugin-win.cpp b/plugins/mpriscontrol/mpriscontrolplugin-win.cpp index 2795068a..a157f319 100644 --- a/plugins/mpriscontrol/mpriscontrolplugin-win.cpp +++ b/plugins/mpriscontrol/mpriscontrolplugin-win.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -56,23 +57,74 @@ QString MprisControlPlugin::randomUrl() { } void MprisControlPlugin::sendMediaProperties(std::variant const& packetOrName, GlobalSystemMediaTransportControlsSession const& player) { - NetworkPacket np = packetOrName.index() == 0 ? std::get<0>(packetOrName) : NetworkPacket(PACKET_TYPE_MPRIS); - if(packetOrName.index() == 1) - np.set(QStringLiteral("player"), std::get<1>(packetOrName)); + std::shared_ptr np = std::make_shared((packetOrName.index() == 0) ? std::get<0>(packetOrName) : NetworkPacket(PACKET_TYPE_MPRIS)); - auto mediaProperties = player.TryGetMediaPropertiesAsync().get(); + if (packetOrName.index() == 1) { + np->set(QStringLiteral("player"), std::get<1>(packetOrName)); + } + std::shared_ptr mediaProperties(nullptr); + std::shared_ptr stream(nullptr); + + concurrency::create_task([this, mediaProperties, np, stream, packetOrName, player]() mutable + { + mediaProperties.reset(&player.TryGetMediaPropertiesAsync().get()); + + if(mediaProperties) { + qDebug() << "I ran! TryGetMediaPropertiesAsync"; + } else { + qDebug() << "mediaProperties is still NULLPTR"; + } + + }).then([this, mediaProperties, np, stream, packetOrName, player] + { + if (mediaProperties) { + qDebug() << "I ran! in second.. thing"; + } else { + qDebug() << "mediaProperties was NULL in second"; + } + + np->set(QStringLiteral("title"), QString::fromWCharArray(mediaProperties->Title().c_str())); + np->set(QStringLiteral("artist"), QString::fromWCharArray(mediaProperties->Artist().c_str())); + np->set(QStringLiteral("album"), QString::fromWCharArray(mediaProperties->AlbumTitle().c_str())); + np->set(QStringLiteral("albumArtUrl"), randomUrl()); + np->set(QStringLiteral("nowPlaying"), mediaProperties->Artist().empty() ? QString::fromWCharArray(mediaProperties->Title().c_str()) : (QString::fromWCharArray(mediaProperties->Artist().c_str()) + QStringLiteral(" - ") + QString::fromWCharArray(mediaProperties->Title().c_str()))); + + qDebug() << "gettings stuff.."; + + qDebug() << "gettings stuff.."; + qDebug() << "gettings stuff.."; + qDebug() << "gettings stuff.."; + qDebug() << "gettings stuff.."; + *stream = mediaProperties->Thumbnail().OpenReadAsync().get(); + qDebug() << "got stuff!"; + qDebug() << "got stuff!"; + qDebug() << "got stuff!"; + qDebug() << "got stuff!"; + + }).then([this, np, stream, packetOrName, player] + { + if (stream != NULL && stream->Size() > 0) { + qDebug() << " stream->ContentType().c_str() = " << QString::fromWCharArray(stream->ContentType().c_str()); + qDebug() << "stream->Size() = " << stream->Size(); + IBuffer buffer; + // stream.ReadAsync(buffer, (uint32_t)stream.Size(), InputStreamOptions::None); + // QImage img; + // img.loadFromData(buffer.data(), buffer.Length() , QStringLiteral("png").toStdString().c_str()); + // if (img.save(QStringLiteral("D:/test.png"), QStringLiteral("png").toStdString().c_str())) { + qDebug() << "SUCCESS!"; + // } else { + // qDebug() << "FAILED"; + // } + + np->set(QStringLiteral("url"), QString()); + sendTimelineProperties(*np, player, true); // "length" + + if(packetOrName.index() == 1) + sendPacket(*np); + } + }); - np.set(QStringLiteral("title"), QString::fromWCharArray(mediaProperties.Title().c_str())); - np.set(QStringLiteral("artist"), QString::fromWCharArray(mediaProperties.Artist().c_str())); - np.set(QStringLiteral("album"), QString::fromWCharArray(mediaProperties.AlbumTitle().c_str())); - np.set(QStringLiteral("albumArtUrl"), randomUrl()); - np.set(QStringLiteral("nowPlaying"), mediaProperties.Artist().empty() ? QString::fromWCharArray(mediaProperties.Title().c_str()) : (QString::fromWCharArray(mediaProperties.Artist().c_str()) + QStringLiteral(" - ") + QString::fromWCharArray(mediaProperties.Title().c_str()))); - - np.set(QStringLiteral("url"), QString()); - sendTimelineProperties(np, player, true); // "length" - if(packetOrName.index() == 1) - sendPacket(np); } void MprisControlPlugin::sendPlaybackInfo(std::variant const& packetOrName, GlobalSystemMediaTransportControlsSession const& player) { -- GitLab