WPF application crashes while playing video using VLC lib after sometime in Windows 10

210 views Asked by At

I am using WPF VLC lib for playing video but app abruptly crashed without throwing any exception. I have found some error in event Viewer > Windows log > application.

Fault bucket 1600891151472079635, type 1
Event Name: APPCRASH
Response: Not available
Cab Id: 0

Problem signature:
P1: OMNIplay.exe
P2: 1.0.0.11
P3: 8d524c28
P4: libdcp_plugin.dll
P5: 3.0.16.0
P6: 3a493a41
P7: 40000015
P8: 000fbf77
P9: 
P10: 

Here is the implementation

For play:

private VlcControl _mediaVLCPlayerElement;
private VlcMediaPlayer _vlcMediaPlayer;

var currentAssembly = Assembly.GetEntryAssembly();

var currentDirectory = new FileInfo(currentAssembly.Location).DirectoryName;
var vlcLibDirectory = new DirectoryInfo(System.IO.Path.Combine(currentDirectory, "libvlc", IntPtr.Size == 4 ? "win-x86" : "win-x64"));

var options = new string[]
                {
                    // VLC options can be given here. Please refer to the VLC command line documentation.
                    "avcodec-hw=any"
                };

_mediaVLCPlayerElement = new VlcControl();
Trace.WriteLine("Creating player begins");

_mediaVLCPlayerElement.SourceProvider.CreatePlayer(vlcLibDirectory, options);
Trace.WriteLine("Player Created");

_vlcMediaPlayer = _mediaVLCPlayerElement.SourceProvider.MediaPlayer;
_vlcMediaPlayer.Log += OnLog;
_vlcMediaPlayer.Video.FullScreen = true;
_vlcMediaPlayer.EndReached += OnMediaEnded;
_vlcMediaPlayer.EncounteredError += OnMediaFailed;
_vlcMediaPlayer.Opening += OnMediaOpening;
_vlcMediaPlayer.SetMedia(new Uri(url, UriKind.Absolute), options);
_vlcMediaPlayer.play();

For disposing:

ThreadPool.QueueUserWorkItem(_ => {
                    try
                    {
                        _vlcMediaPlayer.EndReached -= OnMediaEnded;
                        _vlcMediaPlayer.EncounteredError -= OnMediaFailed;
                        _vlcMediaPlayer.Opening -= OnMediaOpening;
                        _vlcMediaPlayer.Log -= OnLog;
                        _vlcMediaPlayer.Stop();
                        _vlcMediaPlayer.GetMedia().Dispose();
                        _vlcMediaPlayer.Dispose();

                        if (_mediaVLCPlayerElement != null)
                        {
                            Trace.WriteLine("Player disposing...");
                            _mediaVLCPlayerElement.SourceProvider.Dispose();
                            _mediaVLCPlayerElement.Dispose();
                            _mediaVLCPlayerElement = null;
                            Trace.WriteLine("Player disposed...");
                        }

                      _vlcMediaPlayer = null;
                    }
                    catch (Exception e)
                    {
                        Trace.WriteLine("Release VLC object: " + e.Message);
                    }
                });

This is happening when disposing the object (when video is completed and trying to start new one).

Please let me know what wrong I am doing here.

Any help would be appreciated. Thanks in advance.

0

There are 0 answers