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)
|
private async void MainWindow_Loaded(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
// Core.Initialize lädt libVLC-Natives (~5-10s) und blockiert sonst den UI-Thread.
|
// 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.
|
// Volume vorab auf UI-Thread lesen, dann Natives auf Background-Thread initialisieren.
|
||||||
await Task.Run(InitializePlayerNatives);
|
var initialVolume = (int)SldVolume.Value;
|
||||||
InitializePlayerUi();
|
await Task.Run(() => InitializePlayerNatives(initialVolume));
|
||||||
|
VideoView.MediaPlayer = _player; // UI-Zuweisung auf UI-Thread
|
||||||
await LoadChannelsAsync();
|
await LoadChannelsAsync();
|
||||||
RestoreLastChannel();
|
RestoreLastChannel();
|
||||||
_ = LoadEpgInBackgroundAsync();
|
_ = LoadEpgInBackgroundAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Schritt 1 (Background-Thread): libVLC-Natives laden. Kein UI-Zugriff.</summary>
|
/// <summary>Background-Thread: libVLC-Natives laden. Kein UI-Zugriff.</summary>
|
||||||
private void InitializePlayerNatives()
|
private void InitializePlayerNatives(int initialVolume)
|
||||||
{
|
{
|
||||||
var exeDir = Path.GetDirectoryName(
|
var exeDir = Path.GetDirectoryName(
|
||||||
System.Reflection.Assembly.GetExecutingAssembly().Location)!;
|
System.Reflection.Assembly.GetExecutingAssembly().Location)!;
|
||||||
|
|
@ -131,13 +132,7 @@ public partial class MainWindow : Window
|
||||||
"--rtsp-tcp"
|
"--rtsp-tcp"
|
||||||
);
|
);
|
||||||
_player = new MediaPlayer(_libVLC);
|
_player = new MediaPlayer(_libVLC);
|
||||||
_player.Volume = (int)SldVolume.Value; // Value-Lesen ist thread-safe (DependencyProperty)
|
_player.Volume = initialVolume;
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Schritt 2 (UI-Thread): MediaPlayer an VideoView binden.</summary>
|
|
||||||
private void InitializePlayerUi()
|
|
||||||
{
|
|
||||||
VideoView.MediaPlayer = _player;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task LoadEpgInBackgroundAsync()
|
private async Task LoadEpgInBackgroundAsync()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue