Skip to content

Instantly share code, notes, and snippets.

@Jj0YzL5nvJ
Jj0YzL5nvJ / cycle-adevice.lua
Last active May 20, 2022 20:37 — forked from bitingsock/cycle-adevice.lua
Cycle through available audio devices with key binds(a,ctrl+a). Change "wasapi" on line 1 to your relevant audio api.
local api = "wasapi"
local deviceList = {}
local function cycle_adevice(s, e, d)
while s ~= e + d do -- until the loop would cycle back to the number we started on
if string.find(mp.get_property("audio-device"), deviceList[s].name, 1, true) then
while true do
if s + d == 0 then --the device list starts at 1; 0 means we iterated to far
s = #deviceList + 1 --so lets restart at the last device
elseif s + d == #deviceList + 1 then --we iterated past the last device
s = 0 --then start from the beginning