unosquare / ffmediaelement

FFME: The Advanced WPF MediaElement (based on FFmpeg)
https://unosquare.github.io/ffmediaelement/
Other
1.17k stars 240 forks source link

Windows form hangs forever when playing video and hit close button #502

Closed namcigar closed 3 years ago

namcigar commented 4 years ago

Windows form hang forever

I used FFME in a simple windows form project (host media element with ElementHost) and it hanged when I play a video and hit Close button. Please help.

Issue Categories

Version Information

Steps to Reproduce

  1. Hit play button:
    private async void btnPlay_Click(object sender, EventArgs e)
        {
            var url = textBox1.Text;
            var target = new Uri(url);
            await mediaElement.Open(target);
            await mediaElement.Play();
        }
  2. Form closing event:
    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            mediaElement.Close();
        }
  3. Hit close button and form will hang forever
  4. Here are log messages:
    [57:35.989 | DBG | Engine.Commands     ] Direct Command 'Close' accepted. Perparing execution.
    [57:36.062 | INF | Container           ] OnStreamReadInterrupt was requested an immediate read exit.
    [57:36.100 | DBG | Engine.Commands     ] Dispose Entered. Waiting for Command Manager processor to stop.
    [57:36.100 | DBG | Engine.Commands     ] Dispose is waiting for pending direct commands.
relliv commented 4 years ago

try this when app closing

mediaElement.Dispose();
namcigar commented 4 years ago

Thank you, I tried that too but it's still the same. As you can see in this log messages:

[11:04.968 | DBG | Engine.Commands     ] Dispose Entered. Waiting for Command Manager processor to stop.
[11:04.968 | DBG | Engine.Commands     ] Dispose is waiting for pending direct commands.
[11:04.968 | DBG | Engine.Commands     ] Dispose is closing media.
[11:04.985 | INF | Container           ] OnStreamReadInterrupt was requested an immediate read exit.

The form is hanged again.

namcigar commented 4 years ago

Any ideas?

relliv commented 4 years ago

I think it is a kind of bug. Bu I have solution (actually ignore). Download source code go to this method and remove all contents, then add return 0; You will not get any more interrupt exceptions. But if you are not using net core app but you can probably get the following error #496.

namcigar commented 4 years ago

Thank you,

I tried another workaround:

Go to this file

Comment out some lines in method OnDisposing() like this:

            // wait for any pending direct commands (unlikely)
            //this.LogDebug(Aspects.EngineCommand, "Dispose is waiting for pending direct commands.");
            //while (IsDirectCommandPending)
            //    Task.Delay(Constants.DefaultTimingPeriod).Wait();

            //this.LogDebug(Aspects.EngineCommand, "Dispose is closing media.");
            try
            {
                // Execute the close media logic directly
                //CommandCloseMedia();
                PostProcessDirectCommand(DirectCommandType.Close, null, false);
            }
            catch (Exception ex)
            {
                this.LogError(Aspects.EngineCommand, "Dispose had issues closing media. This is most likely a bug.", ex);
            }

then it worked!

But I still wondering why so I asked for help from you all.

relliv commented 4 years ago

This package is working fine with local files or hosted (web) files but streaming part isn't good. Stream latency, buffering etc. I think author should fix these parts but he is seems busy.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.