summaryrefslogtreecommitdiffstats
path: root/.config/mpv/scripts/uosc_shared/elements/BufferingIndicator.lua
diff options
context:
space:
mode:
Diffstat (limited to '.config/mpv/scripts/uosc_shared/elements/BufferingIndicator.lua')
-rw-r--r--.config/mpv/scripts/uosc_shared/elements/BufferingIndicator.lua37
1 files changed, 37 insertions, 0 deletions
diff --git a/.config/mpv/scripts/uosc_shared/elements/BufferingIndicator.lua b/.config/mpv/scripts/uosc_shared/elements/BufferingIndicator.lua
new file mode 100644
index 0000000..e2aa071
--- /dev/null
+++ b/.config/mpv/scripts/uosc_shared/elements/BufferingIndicator.lua
@@ -0,0 +1,37 @@
+local Element = require('uosc_shared/elements/Element')
+
+---@class BufferingIndicator : Element
+local BufferingIndicator = class(Element)
+
+function BufferingIndicator:new() return Class.new(self) --[[@as BufferingIndicator]] end
+function BufferingIndicator:init()
+ Element.init(self, 'buffer_indicator')
+ self.ignores_menu = true
+ self.enabled = false
+end
+
+function BufferingIndicator:decide_enabled()
+ local cache = state.cache_underrun or state.cache_buffering and state.cache_buffering < 100
+ local player = state.core_idle and not state.eof_reached
+ if self.enabled then
+ if not player or (state.pause and not cache) then self.enabled = false end
+ elseif player and cache and state.uncached_ranges then self.enabled = true end
+end
+
+function BufferingIndicator:on_prop_pause() self:decide_enabled() end
+function BufferingIndicator:on_prop_core_idle() self:decide_enabled() end
+function BufferingIndicator:on_prop_eof_reached() self:decide_enabled() end
+function BufferingIndicator:on_prop_uncached_ranges() self:decide_enabled() end
+function BufferingIndicator:on_prop_cache_buffering() self:decide_enabled() end
+function BufferingIndicator:on_prop_cache_underrun() self:decide_enabled() end
+
+function BufferingIndicator:render()
+ local ass = assdraw.ass_new()
+ ass:rect(0, 0, display.width, display.height, {color = bg, opacity = 0.3})
+ local size = round(30 + math.min(display.width, display.height) / 10)
+ local opacity = (Elements.menu and not Elements.menu.is_closing) and 0.3 or 0.8
+ ass:spinner(display.width / 2, display.height / 2, size, {color = fg, opacity = opacity})
+ return ass
+end
+
+return BufferingIndicator