SpircHandler.h 1.6 KB

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