Meta.Vlc icon indicating copy to clipboard operation
Meta.Vlc copied to clipboard

stuck in stop

Open xpachin opened this issue 7 years ago • 5 comments

when i exit my app, it always get stuck in this line

VlcMediaPlayer.cs ///

/// 设置 为停止 /// public void Stop() { _stopFunction.Delegate(InstancePointer);<----here! } any solutions? thanks!

xpachin avatar Jul 04 '17 22:07 xpachin

I think you should stop media and release resource before you exit

devkanro avatar Jul 05 '17 03:07 devkanro

that is what in do. but when i stop the media, it get stuck here

xpachin avatar Jul 05 '17 17:07 xpachin

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.

szurgot avatar Jul 15 '17 00:07 szurgot

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.

szurgot avatar Aug 04 '17 19:08 szurgot

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();
        }
    }
});

cc0der avatar Feb 13 '18 10:02 cc0der