Implements seeking to saved position for tracks
This commit is contained in:
+3
-1
@@ -105,8 +105,10 @@ return screen:new{
|
|||||||
local track = database.track_by_id(contents)
|
local track = database.track_by_id(contents)
|
||||||
if (track) then
|
if (track) then
|
||||||
print("Track saved position: ", track.saved_position)
|
print("Track saved position: ", track.saved_position)
|
||||||
end
|
queue.play_from(track.filepath, track.saved_position)
|
||||||
|
else
|
||||||
queue.add(contents)
|
queue.add(contents)
|
||||||
|
end
|
||||||
playback.playing:set(true)
|
playback.playing:set(true)
|
||||||
backstack.push(playing:new())
|
backstack.push(playing:new())
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -106,6 +106,8 @@ struct QueueUpdate : tinyfsm::Event {
|
|||||||
kBulkLoadingUpdate,
|
kBulkLoadingUpdate,
|
||||||
};
|
};
|
||||||
Reason reason;
|
Reason reason;
|
||||||
|
|
||||||
|
std::optional<uint32_t> seek_to_second;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct StepUpVolume : tinyfsm::Event {};
|
struct StepUpVolume : tinyfsm::Event {};
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ auto AudioState::emitPlaybackUpdate(bool paused) -> void {
|
|||||||
void AudioState::react(const QueueUpdate& ev) {
|
void AudioState::react(const QueueUpdate& ev) {
|
||||||
SetTrack cmd{
|
SetTrack cmd{
|
||||||
.new_track = std::monostate{},
|
.new_track = std::monostate{},
|
||||||
.seek_to_second = {},
|
.seek_to_second = ev.seek_to_second,
|
||||||
};
|
};
|
||||||
|
|
||||||
auto current = sServices->track_queue().current();
|
auto current = sServices->track_queue().current();
|
||||||
|
|||||||
@@ -85,6 +85,16 @@ auto notifyChanged(bool current_changed, Reason reason) -> void {
|
|||||||
events::Audio().Dispatch(ev);
|
events::Audio().Dispatch(ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto notifyPlayFrom(uint32_t start_from_position) -> void {
|
||||||
|
QueueUpdate ev{
|
||||||
|
.current_changed = true,
|
||||||
|
.reason = Reason::kExplicitUpdate,
|
||||||
|
.seek_to_second = start_from_position,
|
||||||
|
};
|
||||||
|
events::Ui().Dispatch(ev);
|
||||||
|
events::Audio().Dispatch(ev);
|
||||||
|
}
|
||||||
|
|
||||||
TrackQueue::TrackQueue(tasks::WorkerPool& bg_worker, database::Handle db)
|
TrackQueue::TrackQueue(tasks::WorkerPool& bg_worker, database::Handle db)
|
||||||
: mutex_(),
|
: mutex_(),
|
||||||
bg_worker_(bg_worker),
|
bg_worker_(bg_worker),
|
||||||
@@ -109,6 +119,17 @@ auto TrackQueue::current() const -> TrackItem {
|
|||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto TrackQueue::playFromPosition(const std::string& filepath,
|
||||||
|
uint32_t position) -> void {
|
||||||
|
clear();
|
||||||
|
{
|
||||||
|
const std::unique_lock<std::shared_mutex> lock(mutex_);
|
||||||
|
playlist_.append(filepath);
|
||||||
|
updateShuffler(true);
|
||||||
|
}
|
||||||
|
notifyPlayFrom(position);
|
||||||
|
}
|
||||||
|
|
||||||
auto TrackQueue::currentPosition() const -> size_t {
|
auto TrackQueue::currentPosition() const -> size_t {
|
||||||
const std::shared_lock<std::shared_mutex> lock(mutex_);
|
const std::shared_lock<std::shared_mutex> lock(mutex_);
|
||||||
return position_;
|
return position_;
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ class TrackQueue {
|
|||||||
auto open() -> bool;
|
auto open() -> bool;
|
||||||
auto openPlaylist(const std::string& playlist_file, bool notify = true)
|
auto openPlaylist(const std::string& playlist_file, bool notify = true)
|
||||||
-> bool;
|
-> bool;
|
||||||
|
auto playFromPosition(const std::string& filepath, uint32_t position) -> void;
|
||||||
|
|
||||||
using Item =
|
using Item =
|
||||||
std::variant<database::TrackId, database::TrackIterator, std::string>;
|
std::variant<database::TrackId, database::TrackIterator, std::string>;
|
||||||
|
|||||||
@@ -79,10 +79,24 @@ static auto queue_open_playlist(lua_State* state) -> int {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static auto queue_play_from(lua_State* state) -> int {
|
||||||
|
Bridge* instance = Bridge::Get(state);
|
||||||
|
audio::TrackQueue& queue = instance->services().track_queue();
|
||||||
|
size_t len = 0;
|
||||||
|
const char* str = luaL_checklstring(state, 1, &len);
|
||||||
|
if (!str) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
auto pos = luaL_checkinteger(state, 2);
|
||||||
|
queue.playFromPosition(str, pos);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static const struct luaL_Reg kQueueFuncs[] = {
|
static const struct luaL_Reg kQueueFuncs[] = {
|
||||||
{"add", queue_add},
|
{"add", queue_add},
|
||||||
{"clear", queue_clear},
|
{"clear", queue_clear},
|
||||||
{"open_playlist", queue_open_playlist},
|
{"open_playlist", queue_open_playlist},
|
||||||
|
{"play_from", queue_play_from},
|
||||||
{NULL, NULL}};
|
{NULL, NULL}};
|
||||||
|
|
||||||
static auto lua_queue(lua_State* state) -> int {
|
static auto lua_queue(lua_State* state) -> int {
|
||||||
|
|||||||
Reference in New Issue
Block a user