Object MethodSystem Control

System.mediaControl(command)

Dispatches a media-button down/up pair to Android’s current media target. True means dispatch completed, not that playback succeeded.

Documented for app version 1.0.64Updated:

Detailed Explanation

This section explains when to use the API, how to call it, and which structures it works best with in production flow.

How To Call It

System is a global table: call its functions with a dot (System.<method>(...)), not a colon. Requires Macro Handler 1.0.62 or later.

When To Use It

In system flow, design steps as observe first and act second when the API can affect device state.

Parameters and Return

command: play, pause, play_pause, stop, next, previous. Invalid types/values or rejected dispatch return false; invalid commands have no side effects.

Options and Limits

Does not select a package or player; it uses Android media-key routing. If no media consumer exists, true does not prove that sound started. It dispatches to the current session and is distinct from System.playMedia, which opens media.

Best Combined With

No-Code or Logic: System → Android Actions → Media control. Lua equivalent: Automation.action("media_control", {command="pause"}); failed dispatch raises an error in that higher-level API.

Example Usage

The snippet below is a starter pattern that can be applied directly in runtime flow.

local dispatched = System.mediaControl("pause")
print("Media request dispatched", dispatched)

Copyable Progressive Examples

From foundation to combined usage, each level is provided as a separate code block so you can copy the level you need and adapt it directly.

Foundation

Shows the shortest direct way to call the API.

Foundation
local dispatched = System.mediaControl("pause")
print("Media request dispatched", dispatched)

Simple

Wraps the base call with minimal flow control.

Simple
local stepOk = true
local dispatched = System.mediaControl("pause")
print("Media request dispatched", dispatched)
if stepOk then
  wait(200)
end

Practical Flow

A practical pattern for real macros with pcall, logging, and guards.

Practical Flow
local ok, err = pcall(function()
  local dispatched = System.mediaControl("pause")
  print("Media request dispatched", dispatched)
end)

if not ok then
  print("API step failed: System.mediaControl: " .. tostring(err))
  requestStop()
end

Detailed

This level packages the API into a reusable helper with error reporting.

Detailed
-- In system flow, design steps as observe first and act second when the API can affect device state.
local function run_mediacontrol_step()
  local dispatched = System.mediaControl("pause")
  print("Media request dispatched", dispatched)
end

local ok, err = pcall(run_mediacontrol_step)
if not ok then
  toast("Step failed")
  print(err)
end

Combined

Combines the API with related structures to form a more realistic workflow.

Combined
local dispatched = System.mediaControl("pause")
if not dispatched then error("Media request was not dispatched") end