From c0a8e895f7953e029f591cea685dd1ad240a5a9a Mon Sep 17 00:00:00 2001 From: Frank Skare Date: Wed, 19 Jun 2019 18:22:40 +0200 Subject: [PATCH] - --- mpv.net/mpv/mp.cs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/mpv.net/mpv/mp.cs b/mpv.net/mpv/mp.cs index 4310c9c..560cfd6 100644 --- a/mpv.net/mpv/mp.cs +++ b/mpv.net/mpv/mp.cs @@ -574,20 +574,24 @@ namespace mpvnet else mp.commandv("loadfile", files[i], "append"); + Task.Run(() => LoadFolder()); // user reported race condition + } + + static void LoadFolder() + { Thread.Sleep(50); // user reported race condition - string path = files[0]; - if (files.Length != 1 || !File.Exists(path)) return; - List filesInFolder = Directory.GetFiles(Path.GetDirectoryName(path)).ToList(); - filesInFolder = filesInFolder.Where((file) => + string path = mp.get_property_string("path"); + if (!File.Exists(path) || get_property_int("playlist-count") != 1) return; + List files = Directory.GetFiles(Path.GetDirectoryName(path)).ToList(); + files = files.Where((file) => App.VideoTypes.Contains(Path.GetExtension(file).TrimStart('.').ToLower()) || App.AudioTypes.Contains(Path.GetExtension(file).TrimStart('.').ToLower())).ToList(); - filesInFolder.Sort(new StringLogicalComparer()); - int index = filesInFolder.IndexOf(path); - filesInFolder.Remove(path); - foreach (string i in filesInFolder) + files.Sort(new StringLogicalComparer()); + int index = files.IndexOf(path); + files.Remove(path); + foreach (string i in files) commandv("loadfile", i, "append"); - if (index > 0) - commandv("playlist-move", "0", (index + 1).ToString()); + if (index > 0) commandv("playlist-move", "0", (index + 1).ToString()); } static IntPtr AllocateUtf8IntPtrArrayWithSentinel(string[] arr, out IntPtr[] byteArrayPointers)