-
Notifications
You must be signed in to change notification settings - Fork 0
/
metadatahelper.h
31 lines (28 loc) · 972 Bytes
/
metadatahelper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#ifndef METADATAHELPER_H
#define METADATAHELPER_H
#include <musicdata.h>
#include <QString>
#include <QPixmap>
#include <QMediaPlayer>
#include <QMediaMetaData>
#include <QObject>
#include <QEventLoop>
#include <QTimer>
namespace Player {
static void getMetaDataFromMusic(const QString &filePath,MusicItemData &music,QPixmap *cover){
QMediaPlayer player;
player.setSource(filePath);
QEventLoop event;
QObject::connect(&player,SIGNAL(metaDataChanged()),&event,SLOT(quit()));
QTimer::singleShot(5000,&event,SLOT(quit()));
event.exec();
QMediaMetaData metaData=player.metaData();
music.albumName=metaData.stringValue(QMediaMetaData::AlbumTitle);
music.artist=metaData.stringValue(QMediaMetaData::Author);
music.songName=metaData.stringValue(QMediaMetaData::Title);
music.path=filePath;
cover->loadFromData(metaData.value(QMediaMetaData::CoverArtImage).toByteArray());
event.deleteLater();
}
}
#endif // METADATAHELPER_H