unosquare / ffmediaelement

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

Calling MediaElement.Open from an OnLoaded event causes AccessViolation #623

Open seafraf opened 2 years ago

seafraf commented 2 years ago

Calling MediaElement.Open from an OnLoaded event causes AccessViolation

This is not an urgent issue, hoping by reporting this that it helps discover underlying issues for other people's problems.

I have an application where I have a list of videos to choose from and the first one from the list would have been loaded when the application starts with a call to MediaElement.Open, subsequent calls to MediaElement.Open would cause the application to crash wiht an AccessViolation (native memory issue, ffmpeg related).

In my tests:

Is this issue related to why the Source property is no longer favored?

Issue Categories

Version Information

Steps to Reproduce

  1. Create MediaElement with OnLoaded event
  2. Load a video with MediaElement.Open from the OnLoaded event
  3. Load another video at any time in the future
  4. Application crashes

Expected Results

Sample Code

XAML

<MainWindow>
        <ffme:MediaElement x:Name="videoPlayer" LoadedBehavior="Manual" UnloadedBehavior="Manual" Loaded="OnLoaded"  />
        <Button Click="OnButton" />
</MainWindow>

C

private async void OnLoaded(object _, RoutedEventArgs _)
{
    // video loads fine
    await videoPlayer.Open("a.mp4")
}

private async void OnButton(object _, RoutedEventArgs _)
{
    // video loads preview but then crashes in a second or less
    await videoPlayer.Open("b.mp4")
}
kuangxj commented 1 year ago
<MainWindow>
        <ffme:MediaElement x:Name="videoPlayer" LoadedBehavior="Play" UnloadedBehavior="Manual" Loaded="OnLoaded"  />
        <Button Click="OnButton" />
`</MainWindow>`
private async void OnLoaded(object _, RoutedEventArgs _)
{
    // video loads fine
    await videoPlayer.Open("a.mp4")
}

private async void OnButton(object _, RoutedEventArgs _)
{
    // Try it's
    await videoPlayer.Close();
    // video loads preview but then crashes in a second or less
    await videoPlayer.Open("b.mp4");
}

If the source of the media has not changed, you can try this method 'await videoPlayer.Play()'

// Add in OnLoaded or Init fuction,check out panel in IDE MediaElement.FFmpegMessageLogged += (s, e) => { if (e.MessageType != MediaLogMessageType.Warning && e.MessageType != MediaLogMessageType.Error) return; if (string.IsNullOrWhiteSpace(e.Message) == false && e.Message.ContainsOrdinal("Using non-standard frame rate")) return; Debug.WriteLine(e); };