feat(Player): V2 playback command namespace + segment_duration fix + mode field

F-024 — V1 single-segment fix: when continuous_loop=false, total_duration is
now always overwritten with segment_duration regardless of what the client
sent. Sending total_duration:0 explicitly no longer bypasses the stop timer.
The play-once fallback in onMelodyLoopCompleted is tightened to only fire when
both segment_duration and total_duration are zero.

F-025 — V2 command namespace: PlaybackHandler now registers playback.play and
playback.stop instead of the old root-level playback command. LegacyAdapter
maps V1 { cmd:playback, action:play/stop } to the new V2 names so all deployed
clients keep working without changes.

F-026 — V2 mode field: setMelodyAttributes accepts a mode string (single /
timed / interval / infinite) with a duration field, replacing the ambiguous
continuous_loop + segment_duration + total_duration triplet. V1 timing fields
are still parsed when mode is absent.

Docs: feature-catalog.md entries F-024, F-025, F-026 added.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-07-07 10:30:05 +03:00
co-authored by Claude Sonnet 4.6
parent 7e8d91673f
commit 9f33f90ea9
5 changed files with 131 additions and 12 deletions
@@ -7,11 +7,29 @@
PlaybackHandler::PlaybackHandler(Player& player) : _player(player) {}
std::vector<String> PlaybackHandler::commands() const {
return { "playback" };
return { "playback.play", "playback.stop" };
}
CommandResult PlaybackHandler::execute(const CommandEnvelope& envelope) {
bool ok = _player.command(const_cast<JsonDocument&>(envelope.contents).as<JsonVariant>());
if (envelope.command == "playback.play") return handlePlay(envelope);
if (envelope.command == "playback.stop") return handleStop(envelope);
return CommandResult::err("playback", "Unknown playback command");
}
CommandResult PlaybackHandler::handlePlay(const CommandEnvelope& envelope) {
// Inject action so Player::command() takes the play branch regardless of
// whether it was set by the V1 adapter or arrived as a bare V2 play command.
JsonDocument& contents = const_cast<JsonDocument&>(envelope.contents);
contents["action"] = "play";
bool ok = _player.command(contents.as<JsonVariant>());
if (ok) return CommandResult::ok("playback", "Playback command executed");
return CommandResult::err("playback", "Playback command failed");
}
CommandResult PlaybackHandler::handleStop(const CommandEnvelope& envelope) {
JsonDocument& contents = const_cast<JsonDocument&>(envelope.contents);
contents["action"] = "stop";
bool ok = _player.command(contents.as<JsonVariant>());
if (ok) return CommandResult::ok("playback", "Playback command executed");
return CommandResult::err("playback", "Playback command failed");
}
@@ -14,4 +14,7 @@ public:
private:
Player& _player;
CommandResult handlePlay(const CommandEnvelope& envelope);
CommandResult handleStop(const CommandEnvelope& envelope);
};