Fix #445 chapters that are script created after the media file is loaded

This commit is contained in:
stax76
2022-06-25 13:07:17 +02:00
parent 023c1db417
commit 69a5ba4470
4 changed files with 26 additions and 28 deletions

View File

@@ -11,6 +11,7 @@
- Fix script compatibility with mordenx and mpv-osc-tethys.
- Fix borderless window not resizable with mouse.
- Fix start-size=session not working.
- Fix chapters that are script created after the media file is loaded.
- Width of command palette slightly increased.
- libmpv zhongfly 2022-06-19

View File

@@ -672,7 +672,7 @@ namespace mpvnet
public static void ShowChapters() => App.InvokeOnMainThread(() =>
{
var items = Core.Chapters.Select(i => new CommandPaletteItem(i.Title, i.TimeDisplay, () =>
var items = Core.GetChapters().Select(i => new CommandPaletteItem(i.Title, i.TimeDisplay, () =>
Core.CommandV("seek", i.Time.ToString(CultureInfo.InvariantCulture), "absolute")));
CommandPalette.Instance.SetItems(items);

View File

@@ -74,7 +74,6 @@ namespace mpvnet
public AutoResetEvent VideoSizeAutoResetEvent { get; } = new AutoResetEvent(false);
public IntPtr Handle { get; set; }
public IntPtr NamedHandle { get; set; }
public List<Chapter> Chapters { get; set; } = new List<Chapter>();
public List<MediaTrack> MediaTracks { get; set; } = new List<MediaTrack>();
public List<TimeSpan> BluRayTitles { get; } = new List<TimeSpan>();
public object MediaTracksLock { get; } = new object();
@@ -1450,25 +1449,26 @@ namespace mpvnet
else
MediaTracks = GetTracks();
}
}
lock (Chapters)
public List<Chapter> GetChapters() {
List<Chapter> chapters = new List<Chapter>();
int count = GetPropertyInt("chapter-list/count");
for (int x = 0; x < count; x++)
{
Chapters.Clear();
int count = GetPropertyInt("chapter-list/count");
string title = GetPropertyString($"chapter-list/{x}/title");
double time = GetPropertyDouble($"chapter-list/{x}/time");
for (int x = 0; x < count; x++)
{
string title = GetPropertyString($"chapter-list/{x}/title");
double time = GetPropertyDouble($"chapter-list/{x}/time");
if (string.IsNullOrEmpty(title) ||
(title.Length == 12 && title.Contains(":") && title.Contains(".")))
if (string.IsNullOrEmpty(title) ||
(title.Length == 12 && title.Contains(":") && title.Contains(".")))
title = "Chapter " + (x + 1);
title = "Chapter " + (x + 1);
Chapters.Add(new Chapter() { Title = title, Time = time });
}
chapters.Add(new Chapter() { Title = title, Time = time });
}
return chapters;
}
public void UpdateExternalTracks()

View File

@@ -293,21 +293,18 @@ namespace mpvnet
}
}
lock (Core.Chapters)
var chaptersMenuItem = FindMenuItem("Chapters");
if (chaptersMenuItem != null)
{
var chaptersMenuItem = FindMenuItem("Chapters");
chaptersMenuItem.Items.Clear();
if (chaptersMenuItem != null)
foreach (Chapter chapter in Core.GetChapters())
{
chaptersMenuItem.Items.Clear();
foreach (Chapter chapter in Core.Chapters)
{
var chapterMenuItem = new WpfControls.MenuItem() { Header = chapter.Title };
chapterMenuItem.InputGestureText = chapter.TimeDisplay;
chapterMenuItem.Click += (sender, args) => Core.CommandV("seek", chapter.Time.ToString(CultureInfo.InvariantCulture), "absolute");
chaptersMenuItem.Items.Add(chapterMenuItem);
}
var chapterMenuItem = new WpfControls.MenuItem() { Header = chapter.Title };
chapterMenuItem.InputGestureText = chapter.TimeDisplay;
chapterMenuItem.Click += (sender, args) => Core.CommandV("seek", chapter.Time.ToString(CultureInfo.InvariantCulture), "absolute");
chaptersMenuItem.Items.Add(chapterMenuItem);
}
}
@@ -1333,7 +1330,7 @@ namespace mpvnet
if (CommandPaletteHost == null)
return;
CommandPaletteHost.Width = FontHeight * 27;
CommandPaletteHost.Width = FontHeight * 26;
if (CommandPaletteHost.Width > ClientSize.Width)
CommandPaletteHost.Width = ClientSize.Width;