Startup: libVLC-Init auf Background-Thread, kein UI-Freeze beim Start
This commit is contained in:
parent
c91944e965
commit
6e172484f8
1 changed files with 25 additions and 20 deletions
|
|
@ -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()
|
||||
/// <summary>Schritt 1 (Background-Thread): libVLC-Natives laden. Kein UI-Zugriff.</summary>
|
||||
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)
|
||||
}
|
||||
|
||||
/// <summary>Schritt 2 (UI-Thread): MediaPlayer an VideoView binden.</summary>
|
||||
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue