fist comin
This commit is contained in:
63
player.h
63
player.h
@@ -1,73 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include <QtMultimedia>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
#include <QDebug>
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
#include <QTimer>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QtQmlIntegration/qqmlintegration.h>
|
||||
|
||||
constexpr int metadataFetchTimeout = 10000;
|
||||
constexpr std::string_view metadataEndpoint = "https://youradio.nonamesoft.xyz/youradio/api/status-json.xsl";
|
||||
|
||||
struct Station
|
||||
{
|
||||
Q_GADGET
|
||||
|
||||
Q_PROPERTY(QString name MEMBER m_name);
|
||||
Q_PROPERTY(QString slug MEMBER m_slug);
|
||||
Q_PROPERTY(QString songTitle MEMBER m_songTitle);
|
||||
Q_PROPERTY(int listeners MEMBER m_listeners);
|
||||
|
||||
public:
|
||||
QString m_name;
|
||||
QString m_slug;
|
||||
QString m_songTitle;
|
||||
int m_listeners;
|
||||
};
|
||||
|
||||
class Player : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
QML_SINGLETON
|
||||
QML_ELEMENT
|
||||
|
||||
Q_PROPERTY(bool playing READ playing NOTIFY playingChanged FINAL)
|
||||
Q_PROPERTY(float volume READ volume WRITE setVolume NOTIFY volumeChanged FINAL)
|
||||
Q_PROPERTY(const QList<Station> stations READ stations NOTIFY stationsChanged FINAL)
|
||||
Q_PROPERTY(int currentIndex READ currentIndex NOTIFY currentIndexChanged FINAL)
|
||||
Q_PROPERTY(const Station* currentStation READ currentStation NOTIFY currentStationChanged FINAL)
|
||||
Q_PROPERTY(bool hasVideo READ hasVideo NOTIFY hasVideoChanged FINAL)
|
||||
Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged FINAL)
|
||||
Q_PROPERTY(bool failed READ failed NOTIFY failedChanged FINAL)
|
||||
Q_PROPERTY(bool playing READ playing NOTIFY playingChanged FINAL)
|
||||
Q_PROPERTY(float volume READ volume WRITE setVolume NOTIFY volumeChanged FINAL)
|
||||
|
||||
public:
|
||||
Player(QObject *parent = nullptr);
|
||||
~Player();
|
||||
|
||||
bool playing() const;
|
||||
bool hasVideo() const;
|
||||
bool loading() const;
|
||||
bool failed() const;
|
||||
bool playing() const;
|
||||
float volume() const;
|
||||
|
||||
float volume() const;
|
||||
void setVolume(float newVolume);
|
||||
|
||||
const QList<Station> stations() const;
|
||||
|
||||
const int currentIndex() const;
|
||||
const Station* currentStation() const;
|
||||
|
||||
public slots:
|
||||
void startPlaying(u_int8_t index);
|
||||
void stopPlaying();
|
||||
void loadVideo(QString id);
|
||||
void unloadVideo();
|
||||
void play();
|
||||
void pause();
|
||||
void stop();
|
||||
|
||||
signals:
|
||||
void hasVideoChanged();
|
||||
void loadingChanged();
|
||||
void failedChanged();
|
||||
void playingChanged();
|
||||
void volumeChanged();
|
||||
void stationsChanged();
|
||||
void currentIndexChanged();
|
||||
void currentStationChanged();
|
||||
|
||||
private:
|
||||
QMediaPlayer player;
|
||||
QAudioOutput output;
|
||||
QTimer timer;
|
||||
QNetworkAccessManager manager;
|
||||
|
||||
int m_currentIndex;
|
||||
QList<Station> m_stations;
|
||||
bool m_failed = false;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user