Skip to content

Commit

Permalink
handle VLC exception from unhandled exception event (#360)
Browse files Browse the repository at this point in the history
  • Loading branch information
huynhsontung authored Apr 19, 2024
1 parent bbc90a0 commit cca9003
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 25 deletions.
15 changes: 15 additions & 0 deletions Screenbox/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#nullable enable

using CommunityToolkit.Mvvm.Messaging;
using LibVLCSharp.Shared;
using Microsoft.AppCenter.Analytics;
using Microsoft.Extensions.DependencyInjection;
using Screenbox.Controls;
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions Screenbox/Controls/PlayerElement.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -33,7 +33,7 @@
</UserControl>

<!-- Use -1 bottom margin to avoid white line artifact -->
<local:VideoView
<vlcSharp:VideoView
x:Name="VlcVideoView"
Margin="0,0,0,-1"
Canvas.ZIndex="0"
Expand Down
22 changes: 0 additions & 22 deletions Screenbox/Controls/VideoView.cs

This file was deleted.

1 change: 0 additions & 1 deletion Screenbox/Screenbox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@
<Compile Include="Controls\TimeDisplay.xaml.cs">
<DependentUpon>TimeDisplay.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\VideoView.cs" />
<Compile Include="Controls\VLCLoginDialog.xaml.cs">
<DependentUpon>VLCLoginDialog.xaml</DependentUpon>
</Compile>
Expand Down

0 comments on commit cca9003

Please sign in to comment.