When clicking a track in the file browser, play it

Includes adding a `playback.is_playable` for working out whether or not
a particular file is able to be played
custom
jacqueline 8 months ago
parent af7a70450e
commit 3421bd652c
  1. 8
      lua/file_browser.lua
  2. 1
      src/tangara/lua/file_iterator.cpp
  3. 1
      src/tangara/lua/file_iterator.hpp
  4. 7
      src/tangara/lua/lua_filesystem.cpp
  5. 18
      src/tangara/ui/ui_fsm.cpp

@ -65,11 +65,15 @@ return screen:new {
iterator = filesystem.iterator(item:filepath()), iterator = filesystem.iterator(item:filepath()),
breadcrumb = item:filepath() breadcrumb = item:filepath()
}) })
end elseif item:filepath():match("%.playlist$") then
if item:filepath():match("%.playlist$") then
queue.open_playlist(item:filepath()) queue.open_playlist(item:filepath())
playback.playing:set(true) playback.playing:set(true)
backstack.push(playing:new()) backstack.push(playing:new())
elseif playback.is_playable(item:filepath()) then
queue.clear()
queue.add(item:filepath())
playback.playing:set(true)
backstack.push(playing:new())
end end
end end
end end

@ -79,7 +79,6 @@ auto FileIterator::iterate(bool show_hidden) -> bool {
.index = offset_, .index = offset_,
.isHidden = hidden, .isHidden = hidden,
.isDirectory = (info.fattrib & AM_DIR) > 0, .isDirectory = (info.fattrib & AM_DIR) > 0,
.isTrack = false, // TODO
.filepath = original_path_ + (original_path_.size() > 0 ? "/" : "") + .filepath = original_path_ + (original_path_.size() > 0 ? "/" : "") +
info.fname, info.fname,
.name = info.fname, .name = info.fname,

@ -19,7 +19,6 @@ struct FileEntry {
int index; int index;
bool isHidden; bool isHidden;
bool isDirectory; bool isDirectory;
bool isTrack;
std::string filepath; std::string filepath;
std::string name; std::string name;
}; };

@ -117,12 +117,6 @@ static auto file_entry_is_hidden(lua_State* state) -> int {
return 1; return 1;
} }
static auto file_entry_is_track(lua_State* state) -> int {
lua::FileEntry* entry = check_file_entry(state, 1);
lua_pushboolean(state, entry->isTrack);
return 1;
}
static auto file_entry_name(lua_State* state) -> int { static auto file_entry_name(lua_State* state) -> int {
lua::FileEntry* entry = check_file_entry(state, 1); lua::FileEntry* entry = check_file_entry(state, 1);
lua_pushlstring(state, entry->name.c_str(), entry->name.size()); lua_pushlstring(state, entry->name.c_str(), entry->name.size());
@ -139,7 +133,6 @@ static const struct luaL_Reg kFileEntryFuncs[] = {{"filepath", file_entry_path},
{"name", file_entry_name}, {"name", file_entry_name},
{"is_directory", file_entry_is_dir}, {"is_directory", file_entry_is_dir},
{"is_hidden", file_entry_is_hidden}, {"is_hidden", file_entry_is_hidden},
{"is_track", file_entry_is_track},
{"__tostring", file_entry_name}, {"__tostring", file_entry_name},
{"__gc", file_entry_gc}, {"__gc", file_entry_gc},
{NULL, NULL}}; {NULL, NULL}};

@ -15,6 +15,8 @@
#include "FreeRTOSConfig.h" #include "FreeRTOSConfig.h"
#include "draw/lv_draw_buf.h" #include "draw/lv_draw_buf.h"
#include "drivers/bluetooth.hpp" #include "drivers/bluetooth.hpp"
#include "lauxlib.h"
#include "lua.h"
#include "lvgl.h" #include "lvgl.h"
#include "core/lv_group.h" #include "core/lv_group.h"
@ -609,10 +611,24 @@ void Lua::entry() {
{"discovered_devices", &sBluetoothDiscoveredDevices}, {"discovered_devices", &sBluetoothDiscoveredDevices},
{"known_devices", &sBluetoothKnownDevices}, {"known_devices", &sBluetoothKnownDevices},
}); });
registry.AddPropertyModule("playback", { registry.AddPropertyModule(
"playback",
{
{"playing", &sPlaybackPlaying}, {"playing", &sPlaybackPlaying},
{"track", &sPlaybackTrack}, {"track", &sPlaybackTrack},
{"position", &sPlaybackPosition}, {"position", &sPlaybackPosition},
{"is_playable",
[&](lua_State* s) {
size_t len;
const char* path = luaL_checklstring(s, 1, &len);
auto res = sServices->tag_parser().ReadAndParseTags({path, len});
if (res) {
lua_pushboolean(s, true);
} else {
lua_pushboolean(s, false);
}
return 1;
}},
}); });
registry.AddPropertyModule( registry.AddPropertyModule(
"queue", "queue",

Loading…
Cancel
Save