Meta.Vlc
Meta.Vlc copied to clipboard
stuck in stop
when i exit my app, it always get stuck in this line
VlcMediaPlayer.cs
///
I think you should stop media and release resource before you exit
that is what in do. but when i stop the media, it get stuck here
What version of vlc are you using? I was seeing this behavior with 2.2.4, but upgrading to 2.2.6 seems to have resolved it.
Scratch_ that. I continued to see the problem after after all.
My alternate working theory (that has help up under more testing), is that if the program is in a VLC event handler (position changed, for example) when calling a method on VLC, it can cause it to hang. I was calling Dispatcher.Invoke to update progress, and whenever I hit break on the hanging stop, it was also hung in that method. By calling Dispatcher.InvokeAsync to do the WPF changes, it seems to have overcome that problem for me.
I had a similar problem when using RebuildPlayer()
.
If the user quickly switched files (mixed between images and videos), libVLC would sometimes block on the stop()
-call.
What I did was make sure the RebuildPlayer()
call comes from a thread other than the UI thread (the tip came from the VideoLan Forum). This lead to SystemAccessViolations if separate threads tried to rebuild the player, so I had to additionally lock()
the call to RebuildPlayer()
.
Sounds insane, but now it works flawlessly ;)
// According to https://forum.videolan.org/viewtopic.php?t=106415#p397198
// we need to command libVLC from a thread other than the UI thread
// to make sure it doesn't block in VlcMediaPlayer.Stop()
await Task.Run(() =>
{
// this looks insane, but we just need a new thread for libVLC to
// accept commands from, but can't actually rebuild the player with libVLC in
// a multithreaded manner or we get access violations on destroyed
// instance pointers
lock (playerLock)
{
Player.RebuildPlayer();
if (media != null && File.Exists(media))
{
Player.LoadMedia(media);
Player.Play();
}
}
});