Fix: SldVolume vor Task.Run lesen - kein Cross-Thread DependencyObject Zugriff
This commit is contained in:
parent
6e172484f8
commit
ab1954e28c
1 changed files with 7 additions and 12 deletions
|
|
@ -105,16 +105,17 @@ public partial class MainWindow : Window
|
|||
private async void MainWindow_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// 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();
|
||||
// Volume vorab auf UI-Thread lesen, dann Natives auf Background-Thread initialisieren.
|
||||
var initialVolume = (int)SldVolume.Value;
|
||||
await Task.Run(() => InitializePlayerNatives(initialVolume));
|
||||
VideoView.MediaPlayer = _player; // UI-Zuweisung auf UI-Thread
|
||||
await LoadChannelsAsync();
|
||||
RestoreLastChannel();
|
||||
_ = LoadEpgInBackgroundAsync();
|
||||
}
|
||||
|
||||
/// <summary>Schritt 1 (Background-Thread): libVLC-Natives laden. Kein UI-Zugriff.</summary>
|
||||
private void InitializePlayerNatives()
|
||||
/// <summary>Background-Thread: libVLC-Natives laden. Kein UI-Zugriff.</summary>
|
||||
private void InitializePlayerNatives(int initialVolume)
|
||||
{
|
||||
var exeDir = Path.GetDirectoryName(
|
||||
System.Reflection.Assembly.GetExecutingAssembly().Location)!;
|
||||
|
|
@ -131,13 +132,7 @@ public partial class MainWindow : Window
|
|||
"--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 = initialVolume;
|
||||
}
|
||||
|
||||
private async Task LoadEpgInBackgroundAsync()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue