support both files and ids in `play`

custom
jacqueline 2 years ago
parent 072c2c23e5
commit c124c8f94d
  1. 30
      src/app_console/app_console.cpp

@ -90,22 +90,36 @@ void RegisterListDir() {
esp_console_cmd_register(&cmd); esp_console_cmd_register(&cmd);
} }
// sInstance->playback_->Play(path + argv[1]);
int CmdPlayFile(int argc, char** argv) { 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) { if (argc < 2) {
std::cout << usage << std::endl; std::cout << usage << std::endl;
return 1; return 1;
} }
std::ostringstream path; std::string path_or_id = argv[1];
path << '/' << argv[1]; bool is_id = true;
for (int i = 2; i < argc; i++) { for (const auto& it : path_or_id) {
path << ' ' << argv[i]; if (!std::isdigit(it)) {
is_id = false;
break;
}
} }
events::Dispatch<audio::PlayFile, audio::AudioState>( if (is_id) {
audio::PlayFile{.filename = path.str()}); 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; return 0;
} }

Loading…
Cancel
Save