Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task done
seafraf opened this issue Apr 29, 2022 · 1 comment
Open
1 task done

Comments

@seafraf
Copy link

seafraf commented Apr 29, 2022

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:

  • Delaying the load of the first video by any amount of time fixes this, making the user click the first video themselves fixes my problem, also adding an arbitrary delay to the Loaded event fixes this issue (tested with Task.Delay with a value as low as 1ms)
  • Closing the video seems to work, so I don't think it's to do with any attempts to free memory when changing videos
  • Launching the sample application with a path to the video does not cause a crash when changing videos, I am assuming this is because of how the sample application loads videos using DelegateCommand's

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

Issue Categories

  • Bug/Crash

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

  • No crash

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")
}
@seafraf seafraf changed the title Calling MediaElement.Open from an OnLoaded event causes Calling MediaElement.Open from an OnLoaded event causes AccessViolation Apr 29, 2022
@kuangxj
Copy link

kuangxj commented Jan 14, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants