EUR full-term totals: 1 month €8.99 · 3 months €21.99 · 6 months €35.99 · 12 months €49.99 Compare plans →
Menu

Player apps

Parse complete mpv IPC messages before updating a controller

Design a local controller for partial reads and unsolicited event messages.

A player organises the experience

Treat a read as bytes, not a whole reply

mpv documents line-separated JSON messages. A local socket read is not a guarantee that exactly one complete message arrived. Keep a buffer, identify complete line boundaries and preserve an unfinished remainder for the next read.

Exercise both directions of the boundary

A developer review should include one message split across two reads and two messages received in one read. Add an unsolicited event between replies. The parser should produce complete objects without dropping the second message or decoding an incomplete fragment as a command failure.

Separate an event from a reply before changing a pending action's status. Receiving a valid JSON event does not mean the most recent user command completed. These are proposed acceptance cases, not results from a controller built for this article.

Keep failure visible and local

Define what happens with malformed input, disconnects and player exit. Preserve enough local diagnostic detail to trace the parser without publishing private paths. Framing correctness is one part of a controller; it does not change the protocol's documented insecure, local-control trust boundary.

Questions answered

Does every socket read contain one JSON message?

No. Design for partial messages and several messages in one read.

Does any valid incoming event complete my last command?

No. Handle events separately from correlated command replies.

Sources & further reading

Official references for the subjects discussed. Service terms and device software can change.

Your next step

A better setup starts with the right details.

Tell us your device model, viewing country and the programmes you want to discuss.

Talk on WhatsApp

+44 7532 814802

WhatsApp ↗↑ Top