Player.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #ifndef PLAYER_H
  2. #define PLAYER_H
  3. #include <vector>
  4. #include <string>
  5. #include <math.h>
  6. #include <functional>
  7. #include <atomic>
  8. #include <mutex>
  9. #include "Utils.h"
  10. #include "MercuryManager.h"
  11. #include "TrackReference.h"
  12. #include "Session.h"
  13. #include "SpotifyTrack.h"
  14. #include "AudioSink.h"
  15. #include <mutex>
  16. #include "BellTask.h"
  17. class Player : public bell::Task {
  18. private:
  19. std::shared_ptr<MercuryManager> manager;
  20. SpotifyTrack *currentTrack = nullptr;
  21. SpotifyTrack *nextTrack = nullptr;
  22. std::shared_ptr<AudioSink> audioSink;
  23. std::mutex loadTrackMutex;
  24. WrappedMutex nextTrackMutex;
  25. WrappedMutex currentTrackMutex;
  26. void runTask();
  27. public:
  28. Player(std::shared_ptr<MercuryManager> manager, std::shared_ptr<AudioSink> audioSink);
  29. std::function<void()> endOfFileCallback;
  30. int volume = 255;
  31. uint32_t logVolume;
  32. bool needFlush = false;
  33. std::atomic<bool> isRunning = false;
  34. trackChangedCallback trackChanged;
  35. std::mutex runningMutex;
  36. void setVolume(uint32_t volume);
  37. void handleLoad(std::shared_ptr<TrackReference> track, std::function<void(bool)> &trackLoadedCallback, uint32_t position_ms, bool isPaused);
  38. void pause();
  39. void cancelCurrentTrack();
  40. void seekMs(size_t positionMs);
  41. void feedPCM(uint8_t *data, size_t len);
  42. void play();
  43. void stop();
  44. };
  45. #endif