diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-06-26 10:39:20 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-06-26 10:39:20 +1000 |
| commit | c124c8f94dbdb41a7e535b741fe2d2be8e7346c0 (patch) | |
| tree | 2b2c6baa695d10aeafdf4411093192affa0ca967 | |
| parent | 072c2c23e58d2ef9620c9f4bd7e8d522afdc5cd9 (diff) | |
| download | tangara-fw-c124c8f94dbdb41a7e535b741fe2d2be8e7346c0.tar.gz | |
support both files and ids in `play`
| -rw-r--r-- | src/app_console/app_console.cpp | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/src/app_console/app_console.cpp b/src/app_console/app_console.cpp index 539fea00..b0a90155 100644 --- a/src/app_console/app_console.cpp +++ b/src/app_console/app_console.cpp @@ -90,22 +90,36 @@ void RegisterListDir() { esp_console_cmd_register(&cmd); } -// sInstance->playback_->Play(path + argv[1]); int CmdPlayFile(int argc, char** argv) { - static const std::string usage = "usage: play [file]"; + static const std::string usage = "usage: play [file or id]"; if (argc < 2) { std::cout << usage << std::endl; return 1; } - std::ostringstream path; - path << '/' << argv[1]; - for (int i = 2; i < argc; i++) { - path << ' ' << argv[i]; + std::string path_or_id = argv[1]; + bool is_id = true; + for (const auto& it : path_or_id) { + if (!std::isdigit(it)) { + is_id = false; + break; + } } - events::Dispatch<audio::PlayFile, audio::AudioState>( - audio::PlayFile{.filename = path.str()}); + if (is_id) { + database::TrackId id = std::atoi(argv[1]); + events::Dispatch<audio::PlayTrack, audio::AudioState>( + audio::PlayTrack{.id = id}); + } else { + std::ostringstream path; + path << '/' << argv[1]; + for (int i = 2; i < argc; i++) { + path << ' ' << argv[i]; + } + + events::Dispatch<audio::PlayFile, audio::AudioState>( + audio::PlayFile{.filename = path.str()}); + } return 0; } |
