Skip to content

Commit

Permalink
fix(media): Adjust error reporting on libVLC initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed May 30, 2023
1 parent 04fac01 commit 246621f
Showing 1 changed file with 44 additions and 34 deletions.
78 changes: 44 additions & 34 deletions src/AddIns/Uno.UI.MediaPlayer.Skia.Gtk/GTKMediaPlayer.events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,53 +42,63 @@ private async Task InitializeInner()
{
await Task.Run(() =>
{
if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
try
{
this.Log().Debug($"Creating libvlc");
}
if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
{
this.Log().Debug($"Creating libvlc");
}

_libvlc = new LibVLC(enableDebugLogs: false);
_libvlc = new LibVLC(enableDebugLogs: false);

if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
{
this.Log().Debug($"Creating player");
}
if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
{
this.Log().Debug($"Creating player");
}

_mediaPlayer = new LibVLCSharp.Shared.MediaPlayer(_libvlc);
_mediaPlayer = new LibVLCSharp.Shared.MediaPlayer(_libvlc);

if (TryGetEventManagerProperty(_mediaPlayer, out var playerManagerProperty)
&& playerManagerProperty.GetValue(_mediaPlayer) is { } eventManager)
{
_playerMap.Add(eventManager, new WeakReference<GtkMediaPlayer>(this));
}
else
{
throw new NotSupportedException("This version of libVLC is not supported (Missing EventManager property). Report this to the Uno Platform repository.");
}
if (TryGetEventManagerProperty(_mediaPlayer, out var playerManagerProperty)
&& playerManagerProperty.GetValue(_mediaPlayer) is { } eventManager)
{
_playerMap.Add(eventManager, new WeakReference<GtkMediaPlayer>(this));
}
else
{
throw new NotSupportedException("This version of libVLC is not supported (Missing EventManager property). Report this to the Uno Platform repository.");
}

if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
{
this.Log().Debug($"Creating VideoView");
}
if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
{
this.Log().Debug($"Creating VideoView");
}

_videoView = new VideoView();
_videoView = new VideoView();

_videoViewMap.Add(_videoView, new WeakReference<GtkMediaPlayer>(this));
_videoViewMap.Add(_videoView, new WeakReference<GtkMediaPlayer>(this));

_videoView.VideoSurfaceInteraction += static (s, e) =>
{
if (GetGtkPlayerForVideoView(s, out var target))
{
target.OnVideoViewVideoSurfaceInteraction(s, e);
}
else
_videoView.VideoSurfaceInteraction += static (s, e) =>
{
if (typeof(GtkMediaPlayer).Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
if (GetGtkPlayerForVideoView(s, out var target))
{
target.OnVideoViewVideoSurfaceInteraction(s, e);
}
else
{
typeof(GtkMediaPlayer).Log().Debug($"Unable to process interaction event, the GtkMediaPlayer instance cannot be found");
if (typeof(GtkMediaPlayer).Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
{
typeof(GtkMediaPlayer).Log().Debug($"Unable to process interaction event, the GtkMediaPlayer instance cannot be found");
}
}
};
}
catch(Exception ex)
{
if (typeof(GtkMediaPlayer).Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Error))
{
typeof(GtkMediaPlayer).Log().Error($"Failed to initialize libVLC. See for more details: https://aka.platform.uno/mediaplayerelement", ex);
}
};
}
});

await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
Expand Down

0 comments on commit 246621f

Please sign in to comment.