SpircHandler.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #pragma once
  2. #include <stdint.h> // for uint32_t, uint8_t
  3. #include <functional> // for function
  4. #include <memory> // for shared_ptr, unique_ptr
  5. #include <string> // for string
  6. #include <variant> // for variant
  7. #include <vector> // for vector
  8. #include "CDNAudioFile.h" // for CDNTrackStream, CDNTrackStream::Track...
  9. #include "TrackQueue.h"
  10. #include "protobuf/spirc.pb.h" // for MessageType
  11. namespace cspot {
  12. class TrackPlayer;
  13. struct Context;
  14. class SpircHandler {
  15. public:
  16. SpircHandler(std::shared_ptr<cspot::Context> ctx);
  17. enum class EventType {
  18. PLAY_PAUSE,
  19. VOLUME,
  20. TRACK_INFO,
  21. DISC,
  22. NEXT,
  23. PREV,
  24. SEEK,
  25. DEPLETED,
  26. FLUSH,
  27. PLAYBACK_START
  28. };
  29. typedef std::variant<TrackInfo, int, bool> EventData;
  30. struct Event {
  31. EventType eventType;
  32. EventData data;
  33. };
  34. typedef std::function<void(std::unique_ptr<Event>)> EventHandler;
  35. void subscribeToMercury();
  36. std::shared_ptr<TrackPlayer> getTrackPlayer();
  37. void setEventHandler(EventHandler handler);
  38. void setPause(bool pause);
  39. void previousSong();
  40. void nextSong();
  41. void notifyAudioReachedPlayback();
  42. void updatePositionMs(uint32_t position);
  43. void setRemoteVolume(int volume);
  44. void loadTrackFromURI(const std::string& uri);
  45. std::shared_ptr<cspot::TrackQueue> getTrackQueue() { return trackQueue; }
  46. void disconnect();
  47. private:
  48. std::shared_ptr<cspot::Context> ctx;
  49. std::shared_ptr<cspot::TrackPlayer> trackPlayer;
  50. std::shared_ptr<cspot::TrackQueue> trackQueue;
  51. EventHandler eventHandler = nullptr;
  52. std::shared_ptr<cspot::PlaybackState> playbackState;
  53. void sendCmd(MessageType typ);
  54. void sendEvent(EventType type);
  55. void sendEvent(EventType type, EventData data);
  56. void skipSong(TrackQueue::SkipDirection dir);
  57. void handleFrame(std::vector<uint8_t>& data);
  58. void notify();
  59. };
  60. } // namespace cspot