-
Notifications
You must be signed in to change notification settings - Fork 0
/
mymediaplayer.cpp
74 lines (56 loc) · 1.86 KB
/
mymediaplayer.cpp
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "mymediaplayer.h"
#include <QVariant>
#include <QDebug>
#include <QImage>
#include <QString>
MyMediaPlayer::MyMediaPlayer(QObject *parent) :
QMediaPlayer(parent)
{
state = QMediaPlayer::StoppedState;
QObject::connect(this, SIGNAL(stateChanged(QMediaPlayer::State)), this, SLOT(getState(QMediaPlayer::State)));
//send meta data
QObject::connect(this, SIGNAL(metaDataChanged()), this, SLOT(sendMetaData()));
//send a expect lyrics
QObject::connect(this, SIGNAL(metaDataChanged()), this, SLOT(sendLyricsPath()));
}
void MyMediaPlayer::setPlayerPositionValue(int pos)
{
this->setPosition(static_cast<qint64>(pos));
}
void MyMediaPlayer::getState(QMediaPlayer::State sta)
{
qDebug() << "current player state:" << sta;
state = sta;
}
void MyMediaPlayer::setPlayerState()
{
//qDebug() << state;
if (state == QMediaPlayer::StoppedState || state == QMediaPlayer::PausedState)
this->play();
else if (state == QMediaPlayer::PlayingState)
this->pause();
else
qDebug() << "set state error";
}
void MyMediaPlayer::sendMetaData()
{
//qDebug() << metaData("Year").toInt();
//qDebug() << metaData("Title").toString();
data.coverArtImage = this->metaData("ThumbnailImage").value<QImage>();
data.title = this->metaData("Title").toString();
data.author = this->metaData("Author").toString();
data.albumTitle = this->metaData("AlbumTitle").toString();
data.year = this->metaData("Year").toString();
emit flashMetaData(data);
}
void MyMediaPlayer::sendLyricsPath()
{
QString lyricsPath = this->currentMedia().canonicalUrl().path();
lyricsPath.remove(0, 1);
int i = lyricsPath.size() - 1;
while (i >= 0 && lyricsPath[i] != '.')
i--;
lyricsPath.remove(i, lyricsPath.size() - i);
lyricsPath.push_back(tr(".lrc"));
emit expectLyricsPath(lyricsPath);
}