File: ao-null-reload.lua

package info (click to toggle)
mpv 0.40.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,676 kB
  • sloc: ansic: 152,062; python: 1,228; sh: 646; javascript: 612; cpp: 461; objc: 302; pascal: 49; xml: 29; makefile: 19
file content (22 lines) | stat: -rw-r--r-- 825 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
-- Handles the edge case where previous attempts to init audio have failed, but
-- might start working due to a newly added device. This is required in
-- particular for ao=wasapi, since the internal IMMNotificationClient code that
-- normally triggers ao-reload will not be running in this case.

local reloading

local function do_reload()
    mp.command("ao-reload")
    reloading = nil
end

local function on_audio_device_list_change()
    if mp.get_property("current-ao") == "null" and not reloading then
        mp.msg.verbose("audio-device-list changed: reloading audio")
        -- avoid calling ao-reload too often
        reloading = mp.add_timeout(0.5, do_reload)
    end
end

mp.set_property("options/audio-fallback-to-null", "yes")
mp.observe_property("audio-device-list", "native", on_audio_device_list_change)