Media
What is playing on the PC, and its controls.
media.session([app_filter]) -> MediaSession | nilThe system media session (Windows media controls): app_filter is a case-insensitive part of the app id ("spotify"); nil = the current session. Read from a cached snapshot that follows the system's change events, so it is cheap every frame; nil until the first snapshot, when nothing plays media, or on Windows without media sessions.
| Name | Type | Description |
|---|---|---|
app_filteroptional | string |
MediaSession | nil
local s = media.session("spotify")
if s then draw.text(20, 20, s.artist .. " - " .. s.title, color(255, 255, 255)) endmedia.sessions() -> table[]Every media session: {app, title, artist, playing}.
table[]
for _, s in ipairs(media.sessions()) do log.info(s.app .. ": " .. s.title) endmedia.play_pause([app_filter]) -> booleanToggles play / pause. True when the request was queued (a matching session allows it); the app applies it a moment later.
| Name | Type | Description |
|---|---|---|
app_filteroptional | string |
boolean
media.play_pause("spotify")media.next([app_filter]) -> booleanSkips to the next track.
| Name | Type | Description |
|---|---|---|
app_filteroptional | string |
boolean
media.next("spotify")media.previous([app_filter]) -> booleanGoes to the previous track (most apps restart the current one first).
| Name | Type | Description |
|---|---|---|
app_filteroptional | string |
boolean
media.previous("spotify")media.seek(seconds [, app_filter]) -> booleanMoves the playback position (clamped to 0..duration).
| Name | Type | Description |
|---|---|---|
seconds | number | |
app_filteroptional | string |
boolean
media.seek(s.duration * 0.5, "spotify")Source app id ("Spotify.exe").
string
Track title ("" if unknown).
string
Artist ("" if unknown).
string
Album ("" if unknown).
string
Playing (false when paused or stopped).
boolean
Seconds into the track, advanced smoothly while playing.
number
Track length in seconds (0 if unknown).
number
media.play_pause is allowed.
boolean
media.next is allowed.
boolean
media.previous is allowed.
boolean
media.seek is allowed.
boolean
The cover art for draw.image (at most 256 px a side), nil until loaded. After a track change the previous cover stays until the new one is ready (up to 3 s). Read it each frame: a script holds the 4 covers it read most recently and older handles are recycled; a 5th different cover in one frame is nil.
image | nil
time.now() when the track last changed.
number