playback_control.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #pragma once
  2. #include "esp_err.h"
  3. #include <stdbool.h>
  4. /**
  5. * Source-agnostic playback controller.
  6. *
  7. * Routes hardware button actions to the correct backend (AirPlay or
  8. * Bluetooth) and notifies the remote client of changes.
  9. *
  10. * For AirPlay: applies volume/pause locally, then sends DACP commands
  11. * to the iOS/macOS client so its UI stays in sync.
  12. *
  13. * For Bluetooth: sends AVRCP passthrough commands to the source device,
  14. * which controls playback and sends volume back via absolute volume.
  15. */
  16. typedef enum {
  17. PLAYBACK_SOURCE_NONE,
  18. PLAYBACK_SOURCE_AIRPLAY,
  19. PLAYBACK_SOURCE_BLUETOOTH,
  20. } playback_source_t;
  21. /**
  22. * Initialize playback control module.
  23. */
  24. esp_err_t playback_control_init(void);
  25. /**
  26. * Set the current audio source. Called by main.c when AirPlay or
  27. * Bluetooth connects/disconnects.
  28. */
  29. void playback_control_set_source(playback_source_t source);
  30. /**
  31. * Get the current audio source.
  32. */
  33. playback_source_t playback_control_get_source(void);
  34. /**
  35. * Toggle play/pause.
  36. */
  37. void playback_control_play_pause(void);
  38. /**
  39. * Increase volume by one step (~3 dB).
  40. */
  41. void playback_control_volume_up(void);
  42. /**
  43. * Decrease volume by one step (~3 dB).
  44. */
  45. void playback_control_volume_down(void);
  46. /**
  47. * Skip to next track.
  48. */
  49. void playback_control_next(void);
  50. /**
  51. * Skip to previous track.
  52. */
  53. void playback_control_prev(void);
  54. /**
  55. * Toggle mute/unmute (AirPlay only — mirrors local mute logic from play/pause).
  56. */
  57. void playback_control_toggle_mute(void);
  58. /**
  59. * Check if currently muted.
  60. */
  61. bool playback_control_is_muted(void);
  62. /**
  63. * Get the current volume as a percentage (0..100), derived from the saved
  64. * AirPlay volume in NVS. Returns 0 when muted.
  65. */
  66. int playback_control_get_volume_percent(void);
  67. /**
  68. * Set current absolute volume as percentage (0..100).
  69. */
  70. void playback_control_set_volume_percent(int percent);