支持频谱显示,感谢哈哈哈群友的代码

This commit is contained in:
2025-09-05 19:28:01 +08:00
parent 10edbc6402
commit 536ef62412
9 changed files with 1171 additions and 3571 deletions

View File

@@ -26,6 +26,13 @@ struct AudioChunk {
};
class Esp32Music : public Music {
public:
// 显示模式控制 - 移动到public区域
enum DisplayMode {
DISPLAY_MODE_SPECTRUM = 0, // 默认显示频谱
DISPLAY_MODE_LYRICS = 1 // 显示歌词
};
private:
std::string last_downloaded_data_;
std::string current_music_url_;
@@ -39,6 +46,8 @@ private:
std::atomic<int> current_lyric_index_;
std::thread lyric_thread_;
std::atomic<bool> is_lyric_running_;
std::atomic<DisplayMode> display_mode_;
std::atomic<bool> is_playing_;
std::atomic<bool> is_downloading_;
std::thread play_thread_;
@@ -77,13 +86,14 @@ private:
// ID3标签处理
size_t SkipId3Tag(uint8_t* data, size_t size);
int16_t* final_pcm_data_fft = nullptr;
public:
Esp32Music();
~Esp32Music();
virtual bool Download(const std::string& song_name) override;
virtual bool Play() override;
virtual bool Stop() override;
virtual bool Download(const std::string& song_name, const std::string& artist_name) override;
virtual std::string GetDownloadResult() override;
// 新增方法
@@ -91,6 +101,11 @@ public:
virtual bool StopStreaming() override; // 停止流式播放
virtual size_t GetBufferSize() const override { return buffer_size_; }
virtual bool IsDownloading() const override { return is_downloading_; }
virtual int16_t* GetAudioData() override { return final_pcm_data_fft; }
// 显示模式控制方法
void SetDisplayMode(DisplayMode mode);
DisplayMode GetDisplayMode() const { return display_mode_.load(); }
};
#endif // ESP32_MUSIC_H
#endif // ESP32_MUSIC_H