Files
qyouradio/player.h

74 lines
1.8 KiB
C
Raw Normal View History

2025-10-16 19:21:35 +02:00
#pragma once
2025-10-16 23:20:10 +02:00
#include <QtMultimedia>
2025-10-16 19:21:35 +02:00
#include <QDebug>
#include <QObject>
#include <QList>
#include <QTimer>
2025-10-16 19:21:35 +02:00
#include <QtQmlIntegration/qqmlintegration.h>
constexpr int metadataFetchTimeout = 10000;
2025-10-16 23:20:10 +02:00
constexpr std::string_view metadataEndpoint = "https://youradio.nonamesoft.xyz/youradio/api/status-json.xsl";
struct Station
{
Q_GADGET
2025-10-16 23:20:10 +02:00
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);
2025-10-16 23:20:10 +02:00
public:
QString m_name;
QString m_slug;
QString m_songTitle;
int m_listeners;
2025-10-16 23:20:10 +02:00
};
2025-10-16 19:21:35 +02:00
class Player : public QObject
{
Q_OBJECT
QML_SINGLETON
QML_ELEMENT
2025-10-16 23:20:10 +02:00
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)
2025-10-16 19:21:35 +02:00
public:
Player(QObject *parent = nullptr);
~Player();
2025-10-16 23:20:10 +02:00
bool playing() const;
2025-10-16 23:20:10 +02:00
float volume() const;
void setVolume(float newVolume);
const QList<Station> stations() const;
const int currentIndex() const;
const Station* currentStation() const;
2025-10-16 23:20:10 +02:00
public slots:
void startPlaying(u_int8_t index);
void stopPlaying();
signals:
void playingChanged();
void volumeChanged();
void stationsChanged();
void currentIndexChanged();
void currentStationChanged();
2025-10-16 23:20:10 +02:00
private:
QMediaPlayer player;
QAudioOutput output;
QTimer timer;
int m_currentIndex;
QList<Station> m_stations;
2025-10-16 19:21:35 +02:00
};