Repository navigation
Metadata and Notifications
The A2DP Sink can receive information about what is playing on the connected source (e.g. your phone) via AVRC.
You can register a callback which is called when the system receives AVRC metadata (esp_avrc_md_attr_mask_t):
void avrc_metadata_callback(uint8_t id, const uint8_t *text) {
Serial.printf("AVRC metadata rsp: attribute id 0x%x, %s\n", id, text);
}
void setup() {
Serial.begin(115200);
a2dp_sink.set_avrc_metadata_callback(avrc_metadata_callback);
a2dp_sink.start("BT");
}By default you get the most important information. You can adjust this by calling set_avrc_metadata_attribute_mask() before you start the sink, e.g. if you only need the title and the playing time:
a2dp_sink.set_avrc_metadata_attribute_mask(ESP_AVRC_MD_ATTR_TITLE | ESP_AVRC_MD_ATTR_PLAYING_TIME);Note that the second parameter of the callback is actually a char* string: even though ESP_AVRC_MD_ATTR_PLAYING_TIME is documented as the media duration in milliseconds, you need to parse it before doing any math on it. See the bt_music_receiver_with_metadata example.
Similar to the metadata callback, you can register callbacks for selected AVRC notifications (esp_avrc_rn_param_t):
| Method | Provides |
|---|---|
| set_avrc_rn_playstatus_callback() | the playback status (esp_avrc_playback_stat_t) |
| set_avrc_rn_play_pos_callback() | the playback position in ms (uint32_t) |
| set_avrc_rn_track_change_callback() | a track change flag (uint8_t) |
See the bt_music_receiver_playing_status_callbacks example.
You can also be notified about changes of the connection state and the audio state with set_on_connection_state_changed() and set_on_audio_state_changed(). See the bt_music_receiver_status_callback example.
Getting Started
A2DP Sink (Receiver)
- Overview & Examples
- Audio Output & DACs
- Sample Rate
- Volume Control
- AVRC: Controlling your Phone
- Metadata & Notifications
- Performance Optimizations
A2DP Source (Sender)
Common
Background
Help