#pragma once #include // for uint32_t, uint8_t #include // for function #include // for shared_ptr, unique_ptr #include // for string #include // for variant #include // for vector #include "CDNAudioFile.h" // for CDNTrackStream, CDNTrackStream::Track... #include "TrackQueue.h" #include "protobuf/spirc.pb.h" // for MessageType namespace cspot { class TrackPlayer; struct Context; class SpircHandler { public: SpircHandler(std::shared_ptr ctx); enum class EventType { PLAY_PAUSE, VOLUME, TRACK_INFO, DISC, NEXT, PREV, SEEK, DEPLETED, FLUSH, PLAYBACK_START }; typedef std::variant EventData; struct Event { EventType eventType; EventData data; }; typedef std::function)> EventHandler; void subscribeToMercury(); std::shared_ptr getTrackPlayer(); void setEventHandler(EventHandler handler); void setPause(bool pause); bool previousSong(); bool nextSong(); void notifyAudioReachedPlayback(); void notifyAudioEnded(); void updatePositionMs(uint32_t position); void setRemoteVolume(int volume); void loadTrackFromURI(const std::string& uri); std::shared_ptr getTrackQueue() { return trackQueue; } void disconnect(); private: std::shared_ptr ctx; std::shared_ptr trackPlayer; std::shared_ptr trackQueue; EventHandler eventHandler = nullptr; std::shared_ptr playbackState; void sendCmd(MessageType typ); void sendEvent(EventType type); void sendEvent(EventType type, EventData data); bool skipSong(TrackQueue::SkipDirection dir); void handleFrame(std::vector& data); void notify(); }; } // namespace cspot