From cca9003dcc5bf4159a383cba142916057cd981b0 Mon Sep 17 00:00:00 2001 From: Tung Huynh <31434093+huynhsontung@users.noreply.github.com> Date: Thu, 18 Apr 2024 21:32:42 -0700 Subject: [PATCH] handle VLC exception from unhandled exception event (#360) --- Screenbox/App.xaml.cs | 15 +++++++++++++++ Screenbox/Controls/PlayerElement.xaml | 4 ++-- Screenbox/Controls/VideoView.cs | 22 ---------------------- Screenbox/Screenbox.csproj | 1 - 4 files changed, 17 insertions(+), 25 deletions(-) delete mode 100644 Screenbox/Controls/VideoView.cs diff --git a/Screenbox/App.xaml.cs b/Screenbox/App.xaml.cs index 6d6c103d5..318183b4b 100644 --- a/Screenbox/App.xaml.cs +++ b/Screenbox/App.xaml.cs @@ -1,6 +1,7 @@ #nullable enable using CommunityToolkit.Mvvm.Messaging; +using LibVLCSharp.Shared; using Microsoft.AppCenter.Analytics; using Microsoft.Extensions.DependencyInjection; using Screenbox.Controls; @@ -75,11 +76,25 @@ public App() HighContrastAdjustment = ApplicationHighContrastAdjustment.None; Suspending += OnSuspending; + UnhandledException += OnUnhandledException; IServiceProvider services = ConfigureServices(); CommunityToolkit.Mvvm.DependencyInjection.Ioc.Default.ConfigureServices(services); } + private static void OnUnhandledException(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e) + { + if (e.Exception is VLCException + { + Message: "Could not create Direct3D11 device : No compatible adapter found." + }) + { + e.Handled = true; + WeakReferenceMessenger.Default.Send(new CriticalErrorMessage(Strings.Resources.CriticalErrorDirect3D11NotAvailable)); + LogService.Log(e); + } + } + private static IServiceProvider ConfigureServices() { ServiceCollection services = new(); diff --git a/Screenbox/Controls/PlayerElement.xaml b/Screenbox/Controls/PlayerElement.xaml index 8fe644d37..ac46bbc41 100644 --- a/Screenbox/Controls/PlayerElement.xaml +++ b/Screenbox/Controls/PlayerElement.xaml @@ -3,8 +3,8 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:local="using:Screenbox.Controls" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:vlcSharp="using:LibVLCSharp.Platforms.Windows" d:DesignHeight="300" d:DesignWidth="400" mc:Ignorable="d"> @@ -33,7 +33,7 @@ - TimeDisplay.xaml - VLCLoginDialog.xaml