-
Notifications
You must be signed in to change notification settings - Fork 1
/
musicplayer.cpp
72 lines (57 loc) · 1.74 KB
/
musicplayer.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
#include "musicplayer.h"
#include <QMessageBox>
#include <iostream>
using namespace std;
MusicPlayer::MusicPlayer()
{
audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
mediaObject = new Phonon::MediaObject(this);
mediaObject->setTickInterval(1000);
connect(mediaObject, SIGNAL(tick(qint64)),
this, SIGNAL(tick(qint64)));
connect(mediaObject, SIGNAL(finished()),
this, SIGNAL(trackFinished()));
connect(mediaObject, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
this, SLOT(handleErrors(Phonon::State)));
Phonon::createPath(mediaObject, audioOutput);
}
MusicPlayer::~MusicPlayer()
{
delete audioOutput;
delete mediaObject;
}
void MusicPlayer::startPlaying(Phonon::MediaSource track)
{
mediaObject->setCurrentSource(track);
mediaObject->play();
}
void MusicPlayer::stopPlaying()
{
mediaObject->stop();
}
QList<QStringList> MusicPlayer::getMetaData(QList<Phonon::MediaSource> sources)
{
QList<QStringList> metaData;
while (!sources.isEmpty()) {
TagLib::FileRef f(sources.takeFirst().fileName().toStdString().c_str());
TagLib::Tag* tag = f.tag();
QString title = tag->title().toCString();
QString artist = tag->artist().toCString();
QString album = tag->album().toCString();
QString year = QString("%1").arg(tag->year());
QStringList thisMetadata;
thisMetadata << artist << title << album << year;
metaData.append(thisMetadata);
}
return metaData;
}
Phonon::AudioOutput* MusicPlayer::getAudioOutputPtr()
{
return audioOutput;
}
void MusicPlayer::handleErrors(Phonon::State newstate)
{
if (newstate == Phonon::ErrorState) {
emit errorPlayingTrack();
}
}