Uses functionality that was added a month ago for exactly this purpose. Fixes #1237.
Unified · Split
| @@ -0,0 +1,22 @@ | |||
| 1 | -- This script pauses playback when minimizing the window, and resumes playback | ||
| 2 | -- if it's brought back again. If the player was already paused when minimizing, | ||
| 3 | -- then try not to mess with the pause state. | ||
| 4 | |||
| 5 | -- Note: currently works with X11 only. | ||
| 6 | |||
| 7 | local did_minimize = false | ||
| 8 | |||
| 9 | mp.observe_property("window-minimized", "bool", function(name, value) | ||
| 10 | local pause = mp.get_property_native("pause") | ||
| 11 | if value == true then | ||
| 12 | if pause == false then | ||
| 13 | mp.set_property_native("pause", true) | ||
| 14 | did_minimize = true | ||
| 15 | end | ||
| 16 | elseif value == false then | ||
| 17 | if did_minimize and (pause == true) then | ||
| 18 | mp.set_property_native("pause", false) | ||
| 19 | end | ||
| 20 | did_minimize = false | ||
| 21 | end | ||
| 22 | end) | ||