From 6e172484f86f20dba49fb4916c4baf4a4fce4970 Mon Sep 17 00:00:00 2001 From: administrator Date: Mon, 11 May 2026 16:52:50 +0200 Subject: [PATCH] Startup: libVLC-Init auf Background-Thread, kein UI-Freeze beim Start --- MainWindow.xaml.cs | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index e0ee5b0..4de349b 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -104,28 +104,17 @@ public partial class MainWindow : Window private async void MainWindow_Loaded(object sender, RoutedEventArgs e) { - InitializePlayer(); + // Core.Initialize lädt libVLC-Natives (~5-10s) und blockiert sonst den UI-Thread. + // Natives auf Background-Thread, UI-Zuweisung (VideoView) danach auf UI-Thread. + await Task.Run(InitializePlayerNatives); + InitializePlayerUi(); await LoadChannelsAsync(); RestoreLastChannel(); - - // EPG im Hintergrund laden — wird für "Danach"-Anzeige und EPG-Overlay gebraucht _ = LoadEpgInBackgroundAsync(); } - private async Task LoadEpgInBackgroundAsync() - { - if (_epgService.IsCurrent) return; - try - { - await _epgService.LoadAsync(); - // Nach EPG-Load: "Danach" für aktuellen Sender setzen - if (_currentChannel != null) - Dispatcher.BeginInvoke(() => UpdateNextFromEpgService(_currentChannel)); - } - catch { } - } - - private void InitializePlayer() + /// Schritt 1 (Background-Thread): libVLC-Natives laden. Kein UI-Zugriff. + private void InitializePlayerNatives() { var exeDir = Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().Location)!; @@ -139,12 +128,28 @@ public partial class MainWindow : Window "--no-video-title-show", "--no-osd", "--no-snapshot-preview", - "--rtsp-tcp" // RTP over TCP: stabilere Sessions, vermeidet UDP-Routing-Kollisionen - // wenn mehrere Instanzen parallel auf die gleiche FritzBox zugreifen + "--rtsp-tcp" ); _player = new MediaPlayer(_libVLC); + _player.Volume = (int)SldVolume.Value; // Value-Lesen ist thread-safe (DependencyProperty) + } + + /// Schritt 2 (UI-Thread): MediaPlayer an VideoView binden. + private void InitializePlayerUi() + { VideoView.MediaPlayer = _player; - _player.Volume = (int)SldVolume.Value; + } + + private async Task LoadEpgInBackgroundAsync() + { + if (_epgService.IsCurrent) return; + try + { + await _epgService.LoadAsync(); + if (_currentChannel != null) + Dispatcher.BeginInvoke(() => UpdateNextFromEpgService(_currentChannel)); + } + catch { } } private void MainWindow_Closing(object? sender, CancelEventArgs e)