dotfiles/multimedia/.config/mpv/scripts/uosc/elements/BufferingIndicator.lua

40 lines
1.6 KiB
Lua
Raw Normal View History

2024-04-20 07:27:09 +00:00
local Element = require('elements/Element')
2023-05-23 13:31:17 +00:00
---@class BufferingIndicator : Element
local BufferingIndicator = class(Element)
function BufferingIndicator:new() return Class.new(self) --[[@as BufferingIndicator]] end
function BufferingIndicator:init()
2024-04-20 07:27:09 +00:00
Element.init(self, 'buffering_indicator', {ignores_curtain = true, render_order = 2})
2023-05-23 13:31:17 +00:00
self.enabled = false
2024-04-20 07:27:09 +00:00
self:decide_enabled()
2023-05-23 13:31:17 +00:00
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
2024-04-20 07:27:09 +00:00
elseif player and cache and state.uncached_ranges then
self.enabled = true
end
2023-05-23 13:31:17 +00:00
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()
2024-04-20 07:27:09 +00:00
ass:rect(0, 0, display.width, display.height, {color = bg, opacity = config.opacity.buffering_indicator})
2023-05-23 13:31:17 +00:00
local size = round(30 + math.min(display.width, display.height) / 10)
2024-04-20 07:27:09 +00:00
local opacity = (Elements.menu and Elements.menu:is_alive()) and 0.3 or 0.8
2023-05-23 13:31:17 +00:00
ass:spinner(display.width / 2, display.height / 2, size, {color = fg, opacity = opacity})
return ass
end
return BufferingIndicator