What control should I use to play videos in .NET 6 app?

67 Views Asked by At

I want to play a video file in my .NET 6.0 Windows Forms Application. It may be a basic thing. However, I could not get things correctly implemented. I find these on the Microsoft website.

  1. MediaPlayer
  2. Windows Media Player
  3. Media Element

Which one should I use in my .NET 6 project? I tried with the following but could not add these to the form. When I add the first one to the form. It shows an error

cannot convert from 'Windows.Media.Playback.MediaPlayer' to 'System.Windows.Forms.Control'

Code:

MediaPlayer Mp = new MediaPlayer();
MediaElement me = new MediaElement();

For the second one, VS suggests to use System.Windows.Controls (from Presentation Framework). But when I click on the suggested menu, it does not install that. I guess, it may be incompatible.

Meanwhile, I added Windows Media Player (..system32\wmp.dll) from the right menu on Toolsbox -> Choose items -> COM Components. It was added. but not shown in the toolsbox. It too may not be compatible.

It shows a message as: The following controls were successfully added to the toolbox but are not enabled in the active designer: Windows Media Player. Make sure the controls to add are compatible with the current designer and .NET Framework version.

What is the solution to play a simple video file in my .NET 6 app?

The .csproj file contents:

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows10.0.22621.0</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<SupportedOSPlatformVersion>10.0.17763.0</SupportedOSPlatformVersion>
</PropertyGroup>
....
0

There are 0 best solutions below