2
0

SpotifyTrack.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifndef SPOTIFYTRACK_H
  2. #define SPOTIFYTRACK_H
  3. #include <memory>
  4. #include <vector>
  5. #include <iostream>
  6. #include "MercuryManager.h"
  7. #include "Utils.h"
  8. #include "MercuryResponse.h"
  9. #include <fstream>
  10. #include "Crypto.h"
  11. #include <functional>
  12. #include "ChunkedAudioStream.h"
  13. #include "TrackReference.h"
  14. #include "NanoPBHelper.h"
  15. #include "protobuf/metadata.pb.h"
  16. #include <cassert>
  17. #include <atomic>
  18. struct TrackInfo {
  19. std::string name;
  20. std::string album;
  21. std::string artist;
  22. std::string imageUrl;
  23. int duration;
  24. };
  25. typedef std::function<void(TrackInfo&)> trackChangedCallback;
  26. class SpotifyTrack
  27. {
  28. private:
  29. std::shared_ptr<MercuryManager> manager;
  30. void trackInformationCallback(std::unique_ptr<MercuryResponse> response, uint32_t position_ms, bool isPaused);
  31. void episodeInformationCallback(std::unique_ptr<MercuryResponse> response, uint32_t position_ms, bool isPaused);
  32. void requestAudioKey(std::vector<uint8_t> fileId, std::vector<uint8_t> trackId, int32_t trackDuration, uint32_t position_ms, bool isPaused);
  33. bool countryListContains(char *countryList, char *country);
  34. bool canPlayTrack(int altIndex);
  35. Track trackInfo;
  36. Episode episodeInfo;
  37. std::vector<uint8_t> fileId;
  38. std::vector<uint8_t> currentChunkData;
  39. std::vector<uint8_t> currentChunkHeader;
  40. public:
  41. SpotifyTrack(std::shared_ptr<MercuryManager> manager, std::shared_ptr<TrackReference> trackRef, uint32_t position_ms, bool isPaused);
  42. ~SpotifyTrack();
  43. uint64_t reqSeqNum = -1;
  44. std::atomic<bool> loaded = false;
  45. std::function<void()> loadedTrackCallback;
  46. std::unique_ptr<ChunkedAudioStream> audioStream;
  47. trackChangedCallback trackInfoReceived;
  48. audioKeyCallback audioKeyLambda;
  49. mercuryCallback responseLambda;
  50. };
  51. #endif