feat(android): add ai-speaker music player preset page

A self-contained page that drives the ai-speaker MCP server over
Streamable HTTP, so playback can be controlled from the TV remote.

Player state
- player_status is the single source of truth. Polling syncs playing,
  source, title, elapsed, duration, progress and remaining once per
  second while playing, and stops when playback ends.
- Switching tracks opens a short freeze window (pendingSource): the
  server keeps reporting the previous source for a few hundred ms, and
  without the freeze the list highlight would snap back to the old row
  and then jump forward again. While frozen only progress is updated.
- Clicking the row that is already playing is a no-op instead of
  restarting it. force=true is reserved for repeat-one and manual
  prev/next, which must replay even when the source is unchanged.

List rendering
- The list is rebuilt only on boot, after list_music, and on explicit
  refresh. Play state changes go through refreshPlayingMark, which
  toggles classes on existing nodes. Rebuilding on every poll popped the
  entrance animation and reset the remote focus once per second.
- A loading overlay covers the list during the initial load and manual
  refresh, with an 8s timeout so a hung request cannot leave it stuck.

Playback modes
- List loop, shuffle and repeat-one, cycling from one button. prev/next
  use pickByManual so they still move when repeat-one is active.
- Natural end of a track advances according to the mode; the check
  requires elapsed to be within 3s of duration so a manual stop does not
  trigger it.

UI notes
- Volume uses the 0-100 scale the server reports, with remote left/right
  stepping by 1. The UI keeps the requested value rather than the
  returned actual, which the speaker quantizes to roughly 5% steps and
  would otherwise make +1 appear to fall back.
- Icons are inline SVG instead of emoji to match the dark theme.
- Avoids CSS the bundled WebView 84 does not support: inset shorthand
  collapsed the overlay to a small box, and filter on a gradient element
  made the play button disappear when focused.

mcp.sh is a small helper for calling a single MCP tool from the shell.
This commit is contained in:
jmj committed 2026-11-30 11:06:35 +08:00
1 parent 3889b6d910
commit 998327df53
2 files changed
+1890

No files matched your search

File diff suppressed because it is too large. Load diff
Executable
+51
View File
@@ -0,0 +1,51 @@
#!/usr/bin/env bash
# 一次性调用 ai-speaker MCP 工具并打印 JSON 结果
set -uo pipefail
BASE="http://192.168.1.111:8765/mcp"
ORIGIN="http://appassets.androidplatform.net"
SID=$(curl -sS -i -X POST "$BASE" \
-H "Origin: $ORIGIN" \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"probe","version":"1"}}}' \
2>/dev/null | tr -d '\r' | awk -F': ' 'tolower($1)=="mcp-session-id"{print $2; exit}')
if [ -z "$SID" ]; then
echo "ERROR: 未能获取 session id" >&2
exit 1
fi
tool="$1"
args="${2:-{\}}"
curl -sS -X POST "$BASE" \
-H "Origin: $ORIGIN" \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-H "mcp-session-id: $SID" \
-d "{\"jsonrpc\":\"2.0\",\"id\":2,\"method\":\"tools/call\",\"params\":{\"name\":\"$tool\",\"arguments\":$args}}" \
2>&1 | sed 's/^data: //' | grep '^{' | python3 -c "
import json, sys
raw = sys.stdin.read().strip()
if not raw:
print(' (空响应)')
raise SystemExit(1)
d = json.loads(raw)
r = d.get('result')
if r is None:
print(' RPC ERROR:', json.dumps(d.get('error'), ensure_ascii=False))
raise SystemExit(1)
txt = ''
if isinstance(r.get('content'), list):
for c in r['content']:
if isinstance(c, dict) and isinstance(c.get('text'), str):
txt += c['text']
if r.get('isError'):
print(' TOOL ERROR:', txt[:300]); raise SystemExit(1)
try:
print(json.dumps(json.loads(txt), ensure_ascii=False, indent=2))
except Exception:
print(txt[:600])
"