Fixed dbus plugin to report metadata (and also added album art).

This commit is contained in:
casey langen 2020-04-04 19:51:25 -07:00
parent e1884321ff
commit fe8d32f586
3 changed files with 20 additions and 2 deletions

View File

@ -188,6 +188,7 @@ static int get_metadata(sd_bus* bus, const char* path, const char *iface,
// append fields
sd_msg_append_dict(reply, "mpris:trackid", metadata.trackid.c_str(), 'o');
sd_msg_append_dict(reply, "mpris:length", &metadata.length, 'x');
sd_msg_append_dict(reply, "mpris:artUrl", metadata.albumArt.c_str(), 's');
sd_msg_append_strlist_dict(reply, "xesam:artist", metadata.artist.c_str());
sd_msg_append_dict(reply, "xesam:title", metadata.title.c_str(), 's');
sd_msg_append_dict(reply, "xesam:album", metadata.album.c_str(), 's');

View File

@ -4,12 +4,14 @@
#include <map>
#include <vector>
#include <functional>
#include <core/sdk/IEnvironment.h>
extern "C" {
#include <unistd.h>
}
thread_local char localBuffer[1024];
std::string thumbnailPath;
thread_local char localBuffer[4096];
static MPRISRemote remote;
static const std::map<MPRISProperty, const std::vector<const char*>> MPRISPropertyNames =
@ -25,6 +27,12 @@ static std::string GetMetadataString(ITrack* track, const char* key)
return std::string(localBuffer);
}
static std::string GetThumbnailPath(ITrack* track)
{
int64_t thumbnailId = track->GetInt64(track::ThumbnailId);
return thumbnailPath + std::to_string(thumbnailId) + ".jpg";
}
static class MPRISPlugin : public IPlugin {
public:
MPRISPlugin() { }
@ -39,6 +47,13 @@ static class MPRISPlugin : public IPlugin {
int SdkVersion() { return musik::core::sdk::SdkVersion; }
} plugin;
extern "C" void SetEnvironment(IEnvironment* environment) {
if (environment) {
environment->GetPath(PathLibrary, localBuffer, sizeof(localBuffer));
thumbnailPath = std::string(localBuffer) + "/thumbs/";
}
}
extern "C" IPlugin* GetPlugin() {
return &plugin;
}
@ -101,7 +116,7 @@ void MPRISRemote::MPRISDeinit() {
void MPRISRemote::MPRISEmitChange(MPRISProperty prop) {
if (bus) {
char** strv = (char**)(&MPRISPropertyNames.at(prop));
char** strv = (char**)(MPRISPropertyNames.at(prop).data());
std::unique_lock<decltype(sd_mutex)> lock(sd_mutex);
sd_bus_emit_properties_changed_strv(bus, "/org/mpris/MediaPlayer2",
"org.mpris.MediaPlayer2.Player",
@ -181,6 +196,7 @@ struct MPRISMetadataValues MPRISRemote::MPRISGetMetadata() {
metadata.discNumber = curTrack->GetInt32(track::DiscNum);
metadata.trackNumber = curTrack->GetInt32(track::TrackNum);
metadata.length = curTrack->GetInt64(track::Duration)*1000*1000;
metadata.albumArt = GetThumbnailPath(curTrack);
metadata.available = true;
}
}

View File

@ -27,6 +27,7 @@ struct MPRISMetadataValues {
std::string title;
std::string album;
std::string albumArtist;
std::string albumArt;
std::string genre;
std::string comment;
uint32_t trackNumber;