ESPHome 2025.5.0
Loading...
Searching...
No Matches
i2s_audio_media_player.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef USE_ESP32_FRAMEWORK_ARDUINO
4
5#include "../i2s_audio.h"
6
7#include <driver/i2s.h>
8
11#include "esphome/core/gpio.h"
13
14#include <Audio.h>
15
16namespace esphome {
17namespace i2s_audio {
18
25
26class I2SAudioMediaPlayer : public Component, public Parented<I2SAudioComponent>, public media_player::MediaPlayer {
27 public:
28 void setup() override;
29 float get_setup_priority() const override { return esphome::setup_priority::LATE; }
30
31 void loop() override;
32
33 void dump_config() override;
34
35 void set_dout_pin(uint8_t pin) { this->dout_pin_ = pin; }
36 void set_mute_pin(GPIOPin *mute_pin) { this->mute_pin_ = mute_pin; }
37#if SOC_I2S_SUPPORTS_DAC
38 void set_internal_dac_mode(i2s_dac_mode_t mode) { this->internal_dac_mode_ = mode; }
39#endif
40 void set_external_dac_channels(uint8_t channels) { this->external_dac_channels_ = channels; }
41
42 void set_i2s_comm_fmt_lsb(bool lsb) { this->i2s_comm_fmt_lsb_ = lsb; }
43
45
46 bool is_muted() const override { return this->muted_; }
47
48 void start();
49 void stop();
50
51 protected:
52 void control(const media_player::MediaPlayerCall &call) override;
53
54 void mute_();
55 void unmute_();
56 void set_volume_(float volume, bool publish = true);
57
58 void start_();
59 void stop_();
60 void play_();
61
63 std::unique_ptr<Audio> audio_;
64
65 uint8_t dout_pin_{0};
66
67 GPIOPin *mute_pin_{nullptr};
68 bool muted_{false};
70
71#if SOC_I2S_SUPPORTS_DAC
72 i2s_dac_mode_t internal_dac_mode_{I2S_DAC_CHANNEL_DISABLE};
73#endif
75
77
79
81 bool is_announcement_{false};
82};
83
84} // namespace i2s_audio
85} // namespace esphome
86
87#endif // USE_ESP32_FRAMEWORK_ARDUINO
BedjetMode mode
BedJet operating mode.
Helper class to request loop() to be called as fast as possible.
Definition helpers.h:630
Helper class to easily give an object a parent of type T.
Definition helpers.h:538
media_player::MediaPlayerTraits get_traits() override
void control(const media_player::MediaPlayerCall &call) override
void set_volume_(float volume, bool publish=true)
const float LATE
For components that should be initialized at the very end of the setup process.
Definition component.cpp:28
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7