unosquare / ffmediaelement

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

Video Not Showing #652

Closed joergahmann closed 10 months ago

joergahmann commented 10 months ago

Issue Title (page stays black)

I#m coding a video tool for sports with the Windows Template Studio and using the Community Toolkit.MVVM. I finished this with the vlcMediaPlayer and it worked almost fine. I need the Frameback (vlc does not provide) and I like autohiding the controls (which is hard with vlc). So I decided to use the ffmediaelemrnt instead. Almost everything is ok, only the Video is not showing!!

I'm using an observable property

 [ObservableProperty]
 private MediaElement _ffmeMediaElement;

instead of your implementation:

        public MediaElement MediaElement
        {
            get
            {
                if (m_MediaElement == null)
                    m_MediaElement = (Application.Current.MainWindow as MainWindow)?.Media;

                return m_MediaElement;
            }
        }

--> Could this be the problem? How do I get the (Application.Current.MainWindow as MainWindow)? in my case with no mainwindow

When I use a contentcontrol instead: the Video is showing, but the controls are not autohiding anymore

When I compile your WindowsSample, it works completly, but still shows the error Object reference not set to an instance of an object on

I would appreciate any help. Thank you in advance

Issue Categories

Version Information

Steps to Reproduce

  1. Project is compiling
  2. I can control the video: Play, Pause, StepForward ... , I can hear the sound provided by the file, Controls are autohiding
  3. I get 3 xaml-Errors the screen stays black

Expected Results

Sample Code

XAML

<Page>
...
                                        <ffme:MediaElement
                        x:Name="FfmeMediaElement"
                        Background="Gray"
                        IsDesignPreviewEnabled="True"
                        LoadedBehavior="Play"
                        UnloadedBehavior="Manual" />
...
</Page>

C


public partial class VideoGameViewModel : BaseViewModel
{
...
   [ObservableProperty]
   private MediaElement _ffmeMediaElement;
...

    public void OnNavigatedTo(object parameter)
    {
...
        Library.FFmpegDirectory = @"D:\Visual Studio 2022\ffmpeg";
        FfmeMediaElement = new MediaElement();

        _ = VideoOpen(Configuration.InputVideoFile);
    }

    private async Task VideoOpen(string inputFile)
    {
        try
        {
            await FfmeMediaElement.Open(new Uri(inputFile));
        }
        catch (Exception ex)
        {
            MessageBox.Show(
                Application.Current.MainWindow,
                $"Media Failed: {ex.GetType()}\r\n{ex.Message}",
                $"{nameof(MediaElement)} Error",
                MessageBoxButton.OK,
                MessageBoxImage.Error,
                MessageBoxResult.OK);
        }
    }
}

### MediaElement
```batch
FfmeMediaElement = {Position = {00:00:00}, IsPlaying = false, IsOpen = true, Source = {file:///D:/Spielbeobachtung/2021 U19_21WM/2021 U19WM CAN1-MEX.MP4}}```
joergahmann commented 10 months ago

I could solve everything I wanted with the Content Control. Die Player is great.