← Events and errors

Decode live media state

app.handle · app.resolve · exact host payloads
handle("media_state", "app", payload)

Playback truth arrives independently of command acknowledgements and must pass Media.decodeState before its fields are read.

When to use it

Use this for every media_state event, including interruptions, buffering, background changes, and playback errors.

  • A successful command resolve means the request was accepted; it is not the ongoing playback position.
  • A decode failure describes an invalid payload, while state.error describes a valid media state reporting playback failure.
  • Keep the previous decoded state when a new payload is invalid.

Focused example

if action == "media_state" and target == "app" then
    local decoded = Media.decodeState(value)
    if decoded.success then
        mediaState = decoded.state
        mediaMessage = decoded.state.error == nil
            and "Playback updated"
            or "Playback error: " .. decoded.state.error.code
    else
        mediaMessage = "Ignored invalid media state"
    end
end

Complete inventory

View all pages in Events and errors
← Previous: Restore History and opened URLsNext: Correlate asynchronous completions →