From b4632a0b6e28b2e4c5e29724cc70bcea62dc4eb8 Mon Sep 17 00:00:00 2001 From: Frank Skare Date: Sun, 26 Jul 2020 02:19:29 +0200 Subject: [PATCH] fix slow BluRay menu --- Changelog.md | 4 ++++ mpv.net/WinForms/MainForm.cs | 19 +++++++++++-------- mpv.net/mpv/Core.cs | 7 +++++-- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Changelog.md b/Changelog.md index 6a10d5e..ddc067e 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,10 @@ 5.4.8.4 Beta (not yet released) ============ +- BluRays with dozens of titles showed all titles in the menu + which was difficult to choose and also extremely slow. + + 5.4.8.3 Beta ============ diff --git a/mpv.net/WinForms/MainForm.cs b/mpv.net/WinForms/MainForm.cs index 246147d..2504be4 100644 --- a/mpv.net/WinForms/MainForm.cs +++ b/mpv.net/WinForms/MainForm.cs @@ -268,15 +268,18 @@ namespace mpvnet lock (core.BluRayTitles) { + List<(int Index, TimeSpan Len)> items = new List<(int Index, TimeSpan Len)>(); + for (int i = 0; i < core.BluRayTitles.Count; i++) - { - if (core.BluRayTitles[i] != "00:00:00") - { - int tmp = i; - MenuItem.Add(titles.DropDownItems, $"{core.BluRayTitles[i]} ({i})", - () => core.SetBluRayTitle(tmp)); - } - } + items.Add((i, core.BluRayTitles[i])); + + var titleItems = items.OrderByDescending(item => item.Len) + .Take(20).OrderBy(item => item.Index); + + foreach (var item in titleItems) + if (item.Len != TimeSpan.Zero) + MenuItem.Add(titles.DropDownItems, $"{item.Len} ({item.Index})", + () => core.SetBluRayTitle(item.Index)); } } } diff --git a/mpv.net/mpv/Core.cs b/mpv.net/mpv/Core.cs index 46c3c1b..5478597 100644 --- a/mpv.net/mpv/Core.cs +++ b/mpv.net/mpv/Core.cs @@ -80,7 +80,7 @@ namespace mpvnet public List MediaTracks { get; set; } = new List(); public List> Chapters { get; set; } = new List>(); - public List BluRayTitles { get; } = new List(); + public List BluRayTitles { get; } = new List(); public IntPtr Handle { get; set; } public IntPtr WindowHandle { get; set; } @@ -614,7 +614,10 @@ namespace mpvnet if (msg.Contains(" duration: ")) { int start = msg.IndexOf(" duration: ") + 11; - BluRayTitles.Add(msg.Substring(start, 8)); + BluRayTitles.Add(new TimeSpan( + msg.Substring(start, 2).ToInt(), + msg.Substring(start + 3, 2).ToInt(), + msg.Substring(start + 6, 2).ToInt())); } } }