Skip to content

Commit

Permalink
Single file image
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhm committed Aug 17, 2018
1 parent 69a3020 commit 7af4dd7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
26 changes: 10 additions & 16 deletions src/broadcast/mpris/mprisplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ MprisPlayer::MprisPlayer(PlayerManager *pPlayerManager,
m_bComponentsInitialized(false),
m_bPropertiesEnabled(false),
m_pMpris(pMpris),
m_pSettings(pSettings) {
m_pSettings(pSettings),
m_currentCoverArtFile(QDir::tempPath() + "/coverArt.jpg") {
connect(m_pWindow, &MixxxMainWindow::componentsInitialized,
this, &MprisPlayer::mixxxComponentsInitialized);
QMetaObject::Connection connection =
Expand Down Expand Up @@ -342,6 +343,10 @@ void MprisPlayer::requestCoverartUrl(TrackPointer pTrack) {
false,
true);
}
else {
m_currentMetadata.coverartUrl.clear();
broadcastCurrentMetadata();
}
}

void MprisPlayer::slotPlayChanged(DeckAttributes *pDeck, bool playing) {
Expand Down Expand Up @@ -374,10 +379,6 @@ MprisPlayer::~MprisPlayer() {
for (DeckAttributes *attrib : m_deckAttributes) {
delete attrib;
}
for (const QString &image : m_coverArtImages) {
QFile imageFile(image);
imageFile.remove();
}
}

void MprisPlayer::slotPlayPositionChanged(DeckAttributes *pDeck, double position) {
Expand Down Expand Up @@ -445,19 +446,14 @@ void MprisPlayer::slotCoverArtFound(const QObject *requestor,

if (!pixmap.isNull() && requestor == this) {
QImage coverImage = pixmap.toImage();
QByteArray hash = QCryptographicHash::hash(
m_currentMetadata.title.toUtf8() +
m_currentMetadata.artists.at(0).toUtf8(),
QCryptographicHash::Sha1);
QString imagePath = QDir::tempPath() + "/" + hash
+ ".jpg";
m_coverArtImages.append(imagePath);
bool success = coverImage.save(imagePath,"JPG");
m_currentCoverArtFile.open(QIODevice::WriteOnly);
bool success = coverImage.save(&m_currentCoverArtFile,"JPG");
if (!success) {
qDebug() << "Couldn't write metadata cover art";
return;
}
m_currentMetadata.coverartUrl = imagePath;
m_currentCoverArtFile.close();
m_currentMetadata.coverartUrl = QDir::tempPath() + "/coverArt.jpg";
broadcastCurrentMetadata();
}

Expand All @@ -477,5 +473,3 @@ QVariantMap MprisPlayer::getVariantMapMetadata() {
metadata.insert("mpris:artUrl",m_currentMetadata.coverartUrl);
return metadata;
}


2 changes: 1 addition & 1 deletion src/broadcast/mpris/mprisplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,5 @@ class MprisPlayer : public QObject {
};

CurrentMetadata m_currentMetadata;
QLinkedList<QString> m_coverArtImages;
QFile m_currentCoverArtFile;
};

0 comments on commit 7af4dd7

Please sign in to comment.