#pragma once #include #include #include #include #include #include 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 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) public: Player(QObject *parent = nullptr); ~Player(); bool playing() const; float volume() const; void setVolume(float newVolume); const QList stations() const; const int currentIndex() const; const Station* currentStation() const; public slots: void startPlaying(u_int8_t index); void stopPlaying(); signals: void playingChanged(); void volumeChanged(); void stationsChanged(); void currentIndexChanged(); void currentStationChanged(); private: QMediaPlayer player; QAudioOutput output; QTimer timer; int m_currentIndex; QList m_stations; };