summaryrefslogtreecommitdiffstats
path: root/player/lua
diff options
context:
space:
mode:
authorJulian <MyFakeAcc.4@googlemail.com>2016-05-18 05:23:11 +0900
committerwm4 <wm4@nowhere>2017-10-09 20:40:31 +0200
commit2f5ee99509e9537b5272c86799bc15cc5b24e313 (patch)
tree50828b948d0bca82ad3e18690e14642552777255 /player/lua
parentfe5b042b7496d0c80f12f304dfade586ccc6dd2e (diff)
downloadmpv-2f5ee99509e9537b5272c86799bc15cc5b24e313.tar.bz2
mpv-2f5ee99509e9537b5272c86799bc15cc5b24e313.tar.xz
stats: add toggling of stats
You can now either show the stats once or toggle their display. Both are using different key bindings which are additionally configurable now. Please bear in mind that "toggling" means "redraw every x seconds for x seconds". Therefore, this approach is prone to problems especially when something else is printing text to the OSD as well as every of these calls will overwrite each other. This is currently a limitation of mpv. Fixes #18
Diffstat (limited to 'player/lua')
-rw-r--r--player/lua/stats.lua33
1 files changed, 29 insertions, 4 deletions
diff --git a/player/lua/stats.lua b/player/lua/stats.lua
index 65cc41b99a..b9fd6daa93 100644
--- a/player/lua/stats.lua
+++ b/player/lua/stats.lua
@@ -13,8 +13,13 @@ local options = require 'mp.options'
-- Options
local o = {
- ass_formatting = true,
+ -- Default key bindings
+ key_oneshot = "i",
+ key_toggle = "I",
+
duration = 3,
+ redraw_delay = 2, -- acts as duration in the toggling case
+ ass_formatting = true,
debug = false,
-- Text style
@@ -50,7 +55,7 @@ local o = {
options.read_options(o)
-function main()
+function main(duration)
local stats = {
header = "",
file = "",
@@ -77,7 +82,7 @@ function main()
add_video(stats)
add_audio(stats)
- mp.osd_message(join_stats(stats), o.duration)
+ mp.osd_message(join_stats(stats), duration or o.duration)
end
@@ -280,4 +285,24 @@ function b(t)
return o.b1 .. t .. o.b0
end
-mp.add_key_binding("i", mp.get_script_name(), main, {repeatable=true})
+
+local timer = mp.add_periodic_timer(o.redraw_delay - 0.1, function() main(o.redraw_delay) end)
+timer:kill()
+
+function periodic_main()
+ if timer:is_enabled() then
+ timer:kill()
+ mp.osd_message("", 0)
+ else
+ timer:resume()
+ main(o.redraw_delay)
+ end
+end
+
+
+mp.add_key_binding(o.key_oneshot, "display_stats", main, {repeatable=true})
+if pcall(function() timer:is_enabled() end) then
+ mp.add_key_binding(o.key_toggle, "display_stats_toggle", periodic_main, {repeatable=false})
+else
+ print("To use continious display of stats please upgrade mpv")
+end