unosquare / ffmediaelement

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

Nothing is opening #672

Closed Manischi closed 2 weeks ago

Manischi commented 2 weeks ago

Can`t open no one file

I installed ffmpeg, added to PATH, to my projects folder and spec link in 'App Code-Behind.' FFME also.

Issue Categories

Version Information

MainWindow XAML

<Window x:Class="testwpf.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:testwpf"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800"
        xmlns:ffme="clr-namespace:Unosquare.FFME;assembly=ffme.win">
    <Grid>
        <ffme:MediaElement x:Name="Media" Background="Gray" LoadedBehavior="Play" UnloadedBehavior="Manual" />
        <Button Content="Play" Click="Button_Click" VerticalAlignment="Bottom"/>
    </Grid>
</Window>

Code-Behind

using System.Windows;

namespace testwpf
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            await Media.Open(new Uri(@"C:\Users\HouseOfGrace\Desktop\C0020.MP4"));
        }
    }
}

App Code-Behind

using System.Windows;

namespace testwpf
{
    public partial class App : Application
    {
        private void App_OnStartup(object sender, StartupEventArgs e)
        {
            Unosquare.FFME.Library.FFmpegDirectory = @"C:\Users\user\source\repos\testwpf\testwpf\ffmpeg";
        }
    }
}

Project copy

https://github.com/Manischi/testwpf

Result

Nothing. Tried different syntax. If use try-catch no mistakes called. image

pvogt commented 2 weeks ago

I tested your project and had to make some changes to get it to work. In your App.xaml.cs, you need to change to the following:

using System.Windows;
using Unosquare.FFME;

namespace testwpf
{
    public partial class App : Application
    {
        public App()
        {
            Unosquare.FFME.Library.FFmpegDirectory = @"C:\Users\HouseOfGrace\source\repos\testwpf\testwpf\ffmpeg";
        }

        protected override void OnStartup(StartupEventArgs e)
        {
            Task.Run(async () =>
            {
                try
                {
                    // Pre-load FFmpeg
                    await Library.LoadFFmpegAsync();
                }
                catch (Exception ex)
                {
                    var dispatcher = Current?.Dispatcher;
                    if (dispatcher != null)
                    {
                        await dispatcher.BeginInvoke(new Action(() =>
                        {
                            MessageBox.Show(MainWindow,
                                $"Unable to Load FFmpeg Libraries from path:\r\n    {Library.FFmpegDirectory}" +
                                $"\r\nMake sure the above folder contains FFmpeg shared binaries (dll files) for the " +
                                $"applicantion's architecture ({(Environment.Is64BitProcess ? "64-bit" : "32-bit")})" +
                                $"\r\nTIP: You can download builds from https://ffmpeg.org/download.html" +
                                $"\r\n{ex.GetType().Name}: {ex.Message}\r\n\r\nApplication will exit.",
                                "FFmpeg Error",
                                MessageBoxButton.OK,
                                MessageBoxImage.Error);

                            Current?.Shutdown();
                        }));
                    }
                }
            });
        }
    }
}

The try-catch code will let you know if you're using the wrong FFMPEG version, which leads me to the next issue. Since you're using the 4.4.350 Nuget package, you also need to use the 4.4 library files. However, FFMPEG 4.4 is so outdated that hardly any place seems to have the library files for download. I'd recommend going to 7.0 version since that's what Unosquare is currently supporting and working on. This is the 4.4 library I found that worked for me with the above fixes: https://sourceforge.net/projects/avbuild/files/windows-desktop/ffmpeg-4.4-windows-desktop-vs2022-gpl-lite.7z/download

Manischi commented 2 weeks ago

Thank you for quick answer. I thought me should wait a mounth or smth :)

OMG. It`s working.

I thought 4.4.350 lib version is the newest version. Installing 7.0.361-beta.1 helped run the files.

Problem was in different FFME and ffmpeg version libraries.

Thank you again