skeleton command line project
This commit is contained in:
parent
30f0bb27ea
commit
afb5f88ea2
4 changed files with 135 additions and 15 deletions
16
main.cpp
16
main.cpp
|
|
@ -1,26 +1,14 @@
|
|||
#include <QtCore/QCoreApplication>
|
||||
#include <QtCore/QList>
|
||||
#include <phonon/phononnamespace.h>
|
||||
#include <phonon/audiooutput.h>
|
||||
#include <phonon/mediaobject.h>
|
||||
#include <phonon/backendcapabilities.h>
|
||||
|
||||
void startPlayer();
|
||||
#include "player.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
app.setApplicationName("PartyBeat Player");
|
||||
|
||||
startPlayer();
|
||||
Player * player = new Player();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
void startPlayer()
|
||||
{
|
||||
Phonon::AudioOutput * audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory);
|
||||
Phonon::MediaObject * mediaObject = new Phonon::MediaObject(this);
|
||||
QList<Phonon::MediaSource> sources;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,4 +15,8 @@ CONFIG -= app_bundle
|
|||
TEMPLATE = app
|
||||
|
||||
|
||||
SOURCES += main.cpp
|
||||
SOURCES += main.cpp \
|
||||
player.cpp
|
||||
|
||||
HEADERS += \
|
||||
player.h
|
||||
|
|
|
|||
94
player.cpp
Normal file
94
player.cpp
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
#include "player.h"
|
||||
#include <QtDebug>
|
||||
#include <cassert>
|
||||
|
||||
Player::Player(QObject *parent) : QObject(parent)
|
||||
{
|
||||
audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory);
|
||||
mediaObject = new Phonon::MediaObject();
|
||||
metaInformationResolver = new Phonon::MediaObject();
|
||||
|
||||
bool success;
|
||||
success = connect(mediaObject, SIGNAL(stateChanged(Phonon::State, Phonon::State)),
|
||||
this, SLOT(stateChanged(Phonon::State, Phonon::State)));
|
||||
assert(success);
|
||||
|
||||
success = connect(metaInformationResolver, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
|
||||
this, SLOT(metaStateChanged(Phonon::State, Phonon::State)));
|
||||
assert(success);
|
||||
|
||||
success = connect(mediaObject, SIGNAL(currentSourceChanged(const Phonon::MediaSource &)),
|
||||
this, SLOT(sourceChanged(const Phonon::MediaSource &)));
|
||||
assert(success);
|
||||
|
||||
success = connect(mediaObject, SIGNAL(aboutToFinish()), this, SLOT(aboutToFinish()));
|
||||
assert(success);
|
||||
|
||||
Phonon::createPath(mediaObject, audioOutput);
|
||||
|
||||
}
|
||||
|
||||
void Player::stateChanged(Phonon::State newState, Phonon::State oldState)
|
||||
{
|
||||
switch (newState) {
|
||||
case Phonon::ErrorState:
|
||||
if (mediaObject->errorType() == Phonon::FatalError) {
|
||||
qWarning() << tr("FATAL: ") << mediaObject->errorString();
|
||||
} else {
|
||||
qWarning() << tr("ERROR: ") << mediaObject->errorString();
|
||||
}
|
||||
break;
|
||||
case Phonon::PlayingState:
|
||||
break;
|
||||
case Phonon::StoppedState:
|
||||
break;
|
||||
case Phonon::PausedState:
|
||||
break;
|
||||
case Phonon::BufferingState:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Player::sourceChanged(const Phonon::MediaSource &source)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Player::aboutToFinish()
|
||||
{
|
||||
int index = sources.indexOf(mediaObject->currentSource()) + 1;
|
||||
if (sources.size() > index) {
|
||||
mediaObject->enqueue(sources.at(index));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Player::metaStateChanged(Phonon::State newState, Phonon::State oldState)
|
||||
{
|
||||
if (newState == Phonon::ErrorState) {
|
||||
qWarning() << tr("ERROR: ") << metaInformationResolver->errorString();
|
||||
return;
|
||||
}
|
||||
|
||||
if (newState != Phonon::StoppedState && newState != Phonon::PausedState)
|
||||
return;
|
||||
|
||||
if (metaInformationResolver->currentSource().type() == Phonon::MediaSource::Invalid)
|
||||
return;
|
||||
|
||||
QMap<QString, QString> metaData = metaInformationResolver->metaData();
|
||||
|
||||
QString title = metaData.value("TITLE");
|
||||
if (title == "")
|
||||
title = metaInformationResolver->currentSource().fileName();
|
||||
|
||||
QString artist = metaData.value("ARTIST");
|
||||
QString album = metaData.value("ALBUM");
|
||||
QString year = metaData.value("DATE");
|
||||
|
||||
Phonon::MediaSource source = metaInformationResolver->currentSource();
|
||||
int index = sources.indexOf(metaInformationResolver->currentSource()) + 1;
|
||||
if (sources.size() > index) {
|
||||
metaInformationResolver->setCurrentSource(sources.at(index));
|
||||
}
|
||||
}
|
||||
34
player.h
Normal file
34
player.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#ifndef PLAYER_H
|
||||
#define PLAYER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QtCore/QList>
|
||||
#include <phonon/phononnamespace.h>
|
||||
#include <phonon/audiooutput.h>
|
||||
#include <phonon/mediaobject.h>
|
||||
#include <phonon/backendcapabilities.h>
|
||||
|
||||
|
||||
class Player : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Player(QObject *parent = 0);
|
||||
|
||||
private slots:
|
||||
void stateChanged(Phonon::State newState, Phonon::State oldState);
|
||||
void sourceChanged(const Phonon::MediaSource &source);
|
||||
void metaStateChanged(Phonon::State newState, Phonon::State oldState);
|
||||
void aboutToFinish();
|
||||
|
||||
|
||||
private:
|
||||
Phonon::AudioOutput * audioOutput;
|
||||
Phonon::MediaObject * mediaObject;
|
||||
Phonon::MediaObject * metaInformationResolver;
|
||||
QList<Phonon::MediaSource> sources;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // PLAYER_H
|
||||
Loading…
Reference in a new issue