|
ESPHome 2026.5.0b1
|
Abstract base class for media sources MediaSource provides audio data to an orchestrator via the MediaSourceListener interface. More...
#include <media_source.h>
Public Member Functions | |
| virtual | ~MediaSource ()=default |
| virtual bool | play_uri (const std::string &uri)=0 |
| Start playing the given URI Sources should validate the URI and state, returning false if the source is busy. | |
| virtual void | handle_command (MediaSourceCommand command)=0 |
| Handle playback commands; e.g., pause, stop, next, etc. | |
| virtual bool | has_internal_playlist () const |
| Whether this source manages its own playlist internally Smart sources that handle next/previous/repeat/shuffle should override this to return true. | |
| MediaSourceState | get_state () const |
| Get current playback state. | |
| virtual bool | can_handle (const std::string &uri) const =0 |
| Check if this source can handle the given URI Each source must override this to match its supported URI scheme(s). | |
| void | set_listener (MediaSourceListener *listener) |
| Set the listener that receives callbacks from this source. | |
| bool | has_listener () const |
| Check if a listener has been registered. | |
| size_t | write_output (const uint8_t *data, size_t length, uint32_t timeout_ms, const audio::AudioStreamInfo &stream_info) |
| Write audio data to the listener. | |
| virtual void | notify_volume_changed (float volume) |
| Notify the source that volume changed Simple sources ignore this. | |
| virtual void | notify_mute_changed (bool is_muted) |
| Notify the source that mute state changed Simple sources ignore this. | |
| virtual void | notify_audio_played (uint32_t frames, int64_t timestamp) |
| Notify the source about audio that has been played Called when the speaker reports that audio frames have been written to the DAC. | |
Protected Member Functions | |
| void | set_state_ (MediaSourceState state) |
| Update state and notify listener This is the only way to change state_, ensuring listener notifications always fire. | |
| void | request_play_uri_ (const std::string &uri) |
| Request the orchestrator to play a new URI. | |
| void | request_volume_ (float volume) |
| Request the orchestrator to change volume. | |
| void | request_mute_ (bool is_muted) |
| Request the orchestrator to change mute state. | |
Abstract base class for media sources MediaSource provides audio data to an orchestrator via the MediaSourceListener interface.
It also receives commands from the orchestrator to control playback.
Definition at line 61 of file media_source.h.
|
virtualdefault |
|
pure virtual |
Check if this source can handle the given URI Each source must override this to match its supported URI scheme(s).
| uri | URI to check |
Implemented in esphome::audio_file::AudioFileMediaSource, esphome::audio_http::AudioHTTPMediaSource, and esphome::sendspin_::SendspinMediaSource.
|
inline |
Get current playback state.
Definition at line 89 of file media_source.h.
|
pure virtual |
Handle playback commands; e.g., pause, stop, next, etc.
| command | Command to execute |
Implemented in esphome::audio_file::AudioFileMediaSource, esphome::audio_http::AudioHTTPMediaSource, and esphome::sendspin_::SendspinMediaSource.
|
inlinevirtual |
Whether this source manages its own playlist internally Smart sources that handle next/previous/repeat/shuffle should override this to return true.
Reimplemented in esphome::sendspin_::SendspinMediaSource.
Definition at line 82 of file media_source.h.
|
inline |
Check if a listener has been registered.
Definition at line 106 of file media_source.h.
|
inlinevirtual |
Notify the source about audio that has been played Called when the speaker reports that audio frames have been written to the DAC.
Sources can override this to track playback progress for synchronization.
| frames | Number of audio frames that were played |
| timestamp | System time in microseconds when the frames finished writing to the DAC |
Reimplemented in esphome::sendspin_::SendspinMediaSource.
Definition at line 139 of file media_source.h.
|
inlinevirtual |
Notify the source that mute state changed Simple sources ignore this.
Override for smart sources that track mute state.
| is_muted | New mute state |
Reimplemented in esphome::sendspin_::SendspinMediaSource.
Definition at line 132 of file media_source.h.
|
inlinevirtual |
Notify the source that volume changed Simple sources ignore this.
Override for smart sources that track volume state.
| volume | New volume level (0.0 to 1.0) |
Reimplemented in esphome::sendspin_::SendspinMediaSource.
Definition at line 127 of file media_source.h.
|
pure virtual |
Start playing the given URI Sources should validate the URI and state, returning false if the source is busy.
The orchestrator is responsible for stopping active sources before starting a new one.
| uri | URI to play; e.g., "http://stream_url" |
Implemented in esphome::audio_file::AudioFileMediaSource, esphome::audio_http::AudioHTTPMediaSource, and esphome::sendspin_::SendspinMediaSource.
|
inlineprotected |
Request the orchestrator to change mute state.
Definition at line 175 of file media_source.h.
|
inlineprotected |
Request the orchestrator to play a new URI.
Definition at line 161 of file media_source.h.
|
inlineprotected |
Request the orchestrator to change volume.
Definition at line 168 of file media_source.h.
|
inline |
Set the listener that receives callbacks from this source.
| listener | Pointer to the MediaSourceListener implementation |
Definition at line 103 of file media_source.h.
|
inlineprotected |
Update state and notify listener This is the only way to change state_, ensuring listener notifications always fire.
Sources running FreeRTOS tasks should signal via event groups and call this from loop().
| state | New state to set |
Definition at line 147 of file media_source.h.
|
inline |
Write audio data to the listener.
| data | Pointer to audio data buffer (not modified by this method) |
| length | Number of bytes to write |
| timeout_ms | Milliseconds to wait if the listener can't accept data immediately |
| stream_info | Audio stream format information |
Definition at line 114 of file media_source.h.