From 2f5ee99509e9537b5272c86799bc15cc5b24e313 Mon Sep 17 00:00:00 2001 From: Julian Date: Wed, 18 May 2016 05:23:11 +0900 Subject: 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 --- player/lua/stats.lua | 33 +++++++++++++++++++++++++++++---- 1 file 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 -- cgit v1.2.3