unosquare / ffmediaelement

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

MediaFailed: Cannot marshal 'parameter' #467

Closed Gikerl closed 4 years ago

Gikerl commented 4 years ago

Issue Title (MediaFailed: Cannot marshal 'parameter')

Full exception message: MediaFailed: Cannot marshal 'parameter #3': Invalid managed/unmanaged type combination (String parameters and return types must be paired with LPStr, LPWStr, LPTStr, BStr, TBStr, VBByRefStr, or AnsiBStr).

This exception occurs after setting the Media.Source only on Windows 7. On Windows 10 the same URI plays just fine.

Issue Categories

Version Information

Steps to Reproduce

  1. Create a WPF Application with the FFME Mediaelement
  2. During Execution change the Media Source
  3. Listen to MediaFailed event and receive the exception (on Windows 7)

Expected Results

Sample Code

XAML

<UserControl x:Class="DeviceView.CameraStreamView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:ffme="clr-namespace:Unosquare.FFME;assembly=ffme.win"
             mc:Ignorable="d" 
             d:DesignHeight="200" d:DesignWidth="267">

    <Grid>
        <ffme:MediaElement  Grid.Row="0" x:Name="Media" Background="Black" LoadedBehavior="Play" 
                            UnloadedBehavior="Manual"/>
    </Grid>
</UserControl>

C

public partial class CameraStreamView
{
    public CameraStreamView()
    {
        Unosquare.FFME.Library.FFmpegDirectory = @"Resources\\FFMpeg\\bin";

        InitializeComponent();

        DataContextChanged += OnDataContextChanged;
        Media.MediaFailed += MediaOnMediaFailed;
    }

    private void MediaOnMediaFailed(object sender, MediaFailedEventArgs e)
    {
        MessageHandling.SendInfo($"{e.ErrorException.Message}");
    }

    private void ChangeMediaSource(Uri newSource)
    {
        Media.Source = newSource
        Media.ChangeMedia();
    }
}
jglk commented 4 years ago

Upgrading .NET Framework to 4.7+ should help. Related issue: https://github.com/Ruslan-B/FFmpeg.AutoGen/issues/119

Gikerl commented 4 years ago

@jglk Thanks, I will try that and see if that fixes the issue. I'll report the result back.

mariodivece commented 4 years ago

Any feedback here before I close?

Gikerl commented 4 years ago

I did not have time to update the project quite yet. I will try to get it done this week and report back!

PhilJenson commented 4 years ago

I have the same problem on Windows 7 & Windows 8 with .net 4.6.1 installed. Installing .net 4.7.1 solves it.

However, our project currently targets .net 4.6.1 which means, when we release an update, this will not work on customers who do not have .net 4.7.1.

As this seems to relate to FFmpeg.AutoGen, in the absence of a fix here, I guess I am going to have to place a warning message in the app to tell customers to upgrade .net. Not ideal.

Gikerl commented 4 years ago

Upgrading to .Net 4.8 fixed the issue.

This means we now have to ship and installer that includes the .Net 4.8 framework.

Edit: Upgrading to .Net Framework 4.8 sadly does not work as there is a known Nuget bug that doesn't copy all referenced dlls to the build directory (https://github.com/NuGet/Home/issues/7440)

Is there another solution for .Net 4.6.2?

mariodivece commented 4 years ago

Unsure how to fix this for FFME specifically. Have you tried filing an issue in the https://github.com/Ruslan-B/FFmpeg.AutoGen project?