Commit 293c32d8 authored by kempe's avatar kempe

#11 Get track information

Added ability to get track information if available from stream
parent 6bad3d3f
#include "audioplayer.h"
#include <QDebug>
AudioPlayer::AudioPlayer(QObject *parent) : QObject(parent)
{
......@@ -12,6 +13,11 @@ AudioPlayer::AudioPlayer(QObject *parent) : QObject(parent)
connect(m_player, &QMediaPlayer::mediaStatusChanged, this, &AudioPlayer::statusChanged);
connect(m_player, &QMediaPlayer::bufferStatusChanged, this, &AudioPlayer::bufferStatusChanged);
connect(m_player, &QMediaPlayer::seekableChanged, this, &AudioPlayer::seekableChanged);
connect(
m_player, static_cast<void(QMediaPlayer::*)()>(&QMediaPlayer::metaDataChanged),
this, &AudioPlayer::metaDataChanged
);
}
AudioPlayer::~AudioPlayer()
......@@ -82,3 +88,22 @@ void AudioPlayer::bufferStatusChanged(const int progress)
m_buffer_progress = progress / 100.0;
emit bufferProgressChanged();
}
void AudioPlayer::metaDataChanged()
{
qDebug() << "metaDataChanged";
QString tmp_title = getMetaDataValueOrEmptyByKey("Title").toString();
if (tmp_title != m_title) {
qDebug() << "Setting title to: " << tmp_title;
m_title = tmp_title;
emit titleChanged();
}
}
QVariant AudioPlayer::getMetaDataValueOrEmptyByKey(QString key) {
if (m_player->availableMetaData().contains(key)) {
return m_player->metaData(key);
}
return "";
}
......@@ -14,6 +14,7 @@ class AudioPlayer : public QObject {
Q_PROPERTY(bool isBuffering READ isBuffering NOTIFY playbackStatusChanged)
Q_PROPERTY(bool isSeekable READ isSeekable NOTIFY seekableChanged)
Q_PROPERTY(double bufferProgress READ bufferProgress NOTIFY bufferProgressChanged)
Q_PROPERTY(QString title READ title NOTIFY titleChanged)
public:
......@@ -25,12 +26,14 @@ public:
bool isBuffering() const { return m_status == QMediaPlayer::BufferingMedia; }
bool isSeekable() const { return m_player->isSeekable(); }
double bufferProgress() const { return m_buffer_progress; }
QString title() const { return m_title; }
signals:
void playbackStateChanged();
void playbackStatusChanged();
void seekableChanged();
void bufferProgressChanged();
void titleChanged();
public slots:
void loadUrl(QString url);
......@@ -40,18 +43,24 @@ private slots:
void stateChanged(QMediaPlayer::State);
void statusChanged(QMediaPlayer::MediaStatus);
void bufferStatusChanged(const int);
void metaDataChanged();
private:
QMediaPlayer *m_player;
// States
QUrl m_current_url;
QMediaPlayer::State m_state;
QMediaPlayer::MediaStatus m_status;
double m_buffer_progress;
QString m_title;
// Playback control
void startPlayback();
void pauseOrStopPlayback();
void stopPlayback();
QVariant getMetaDataValueOrEmptyByKey(QString);
};
static QObject *audioPlayerProvider(QQmlEngine *engine, QJSEngine *scriptEngine)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment