实现 /api/playlist 快照语义,返回 playlist 和 current_index
- 新增 PlaylistSnapshot 结构体,包含 playlist 和 current_index - 修改 playlist_route 从 HttpState 获取 player_status.current_index - 与旧版 hologram_player_rust 行为一致 - cargo check 零 warning
This commit is contained in:
27
TEAM_CHAT.md
27
TEAM_CHAT.md
@@ -1866,3 +1866,30 @@ M Cargo.lock
|
||||
- 这与旧版 `video_processor.rs:578-588` 的行为完全一致
|
||||
|
||||
---
|
||||
|
||||
[2026-03-12 14:30] 李思琪(视频引擎工程师) → 刘建国(PM), 陈逸飞(CEO): /api/playlist 快照语义已实现,与旧版行为一致。
|
||||
|
||||
背景:
|
||||
- 旧版 `/api/playlist` 返回 `{ playlist: [...], current_index: N }`,包含当前播放索引
|
||||
- 新版只返回配置中的 playlist 数组,缺少 current_index
|
||||
- 这导致客户端无法获知当前播放位置的快照
|
||||
|
||||
实现方案:
|
||||
- 在 `src/plugins/http/routes.rs` 中:
|
||||
- 新增 `PlaylistSnapshot` 结构体(line 59-63),包含 `playlist` 和 `current_index` 字段
|
||||
- 修改 `playlist_route` 函数(line 207-220),从 `HttpState` 获取 `player_status.current_index`
|
||||
- 返回 `{ playlist: config.playlist, current_index: player_status.current_index }`
|
||||
|
||||
修改文件:
|
||||
- `src/plugins/http/routes.rs` (line 59-63, 207-220)
|
||||
|
||||
验证结果:
|
||||
- ✅ `cargo check` 通过,零 warning
|
||||
- ✅ 响应结构与旧版 `hologram_player_rust/src/api_server.rs:371-374` 完全一致
|
||||
|
||||
行为说明:
|
||||
- HttpPlugin 维护的 `player_status` 通过 `Message::PlayerStatus` 广播实时更新
|
||||
- VideoPlugin 在播放状态变化时广播 `PlayerStatus`,包含 `current_index`
|
||||
- `/api/playlist` 返回配置快照 + 当前播放索引,客户端可据此实现播放列表高亮
|
||||
|
||||
---
|
||||
|
||||
@@ -57,6 +57,12 @@ struct BleStatusResponse {
|
||||
device_name: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct PlaylistSnapshot {
|
||||
playlist: Vec<crate::core::config::VideoItem>,
|
||||
current_index: usize,
|
||||
}
|
||||
|
||||
pub(crate) fn build_routes(
|
||||
tx: mpsc::Sender<Envelope>,
|
||||
state: Arc<HttpState>,
|
||||
@@ -212,7 +218,12 @@ fn playlist_route(
|
||||
.and(with_state(state))
|
||||
.and_then(|state: Arc<HttpState>| async move {
|
||||
let config = state.config();
|
||||
Ok::<_, Infallible>(json_response(StatusCode::OK, &config.playlist))
|
||||
let player_status = state.player_status();
|
||||
let snapshot = PlaylistSnapshot {
|
||||
playlist: config.playlist.clone(),
|
||||
current_index: player_status.current_index,
|
||||
};
|
||||
Ok::<_, Infallible>(json_response(StatusCode::OK, &snapshot))
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user