From 6ff8b5886ef91ed46dba08686900d519f6c9c62d Mon Sep 17 00:00:00 2001 From: jacqueline Date: Mon, 19 Jun 2023 08:51:34 +1000 Subject: Support playing tracks by track id --- src/audio/fatfs_audio_input.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src/audio/fatfs_audio_input.cpp') diff --git a/src/audio/fatfs_audio_input.cpp b/src/audio/fatfs_audio_input.cpp index c26ff0ad..77b104d3 100644 --- a/src/audio/fatfs_audio_input.cpp +++ b/src/audio/fatfs_audio_input.cpp @@ -8,7 +8,9 @@ #include #include +#include #include +#include #include #include #include @@ -38,6 +40,7 @@ namespace audio { FatfsAudioInput::FatfsAudioInput() : IAudioElement(), + pending_path_(), current_file_(), is_file_open_(false), current_container_(), @@ -45,11 +48,19 @@ FatfsAudioInput::FatfsAudioInput() FatfsAudioInput::~FatfsAudioInput() {} +auto FatfsAudioInput::OpenFile(std::future>&& path) + -> void { + pending_path_ = std::move(path); +} + auto FatfsAudioInput::OpenFile(const std::string& path) -> bool { if (is_file_open_) { f_close(¤t_file_); is_file_open_ = false; } + if (pending_path_) { + pending_path_ = {}; + } ESP_LOGI(kTag, "opening file %s", path.c_str()); database::TagParserImpl tag_parser; @@ -89,16 +100,33 @@ auto FatfsAudioInput::OpenFile(const std::string& path) -> bool { return false; } + events::Dispatch({}); is_file_open_ = true; return true; } auto FatfsAudioInput::NeedsToProcess() const -> bool { - return is_file_open_; + return is_file_open_ || pending_path_; } auto FatfsAudioInput::Process(const std::vector& inputs, OutputStream* output) -> void { + if (pending_path_) { + ESP_LOGI(kTag, "waiting for path"); + if (!pending_path_->valid()) { + pending_path_ = {}; + } else { + if (pending_path_->wait_for(std::chrono::seconds(0)) == + std::future_status::ready) { + ESP_LOGI(kTag, "path ready!"); + auto result = pending_path_->get(); + if (result) { + OpenFile(*result); + } + } + } + } + if (!is_file_open_) { return; } -- cgit v1.2.3