You can do it using old DirectShow functionality.
This answer teaches you how to create QuartzTypeLib.dll
:
Run tlbimp tool (in your case path will be different):
Run TlbImp.exe %windir%\system32\quartz.dll /out:QuartzTypeLib.dll
Alternatively, this project contains the library interop.QuartzTypeLib.dll
, which is basically the same thing as steps 1. and 2. The following steps teach how to use this library:
Add generated QuartzTypeLib.dll as a COM-reference to your project (click right mouse button on the project name in "Solution Explorer", then select "Add" menu item and then "Reference")
In your Project, expand the "References", find the QuartzTypeLib reference. Right click it and select properties, and change "Embed Interop Types" to false. (Otherwise you won't be able to use the FilgraphManager class in your project (and probably a couple of other ones)).
In Project Settings, in the Build tab, I had to disable the Prefer 32-bit flag, Otherwise I would get this Exception: System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x80040266
Use this class to play your favorite MP3 file:
using QuartzTypeLib;
public sealed class DirectShowPlayer
{
private FilgraphManager FilterGraph;
public void Play(string path)
{
FilgraphManager = new FilgraphManager();
FilterGraph.RenderFile(path);
FilterGraph.Run();
}
public void Stop()
{
FilterGraph?.Stop();
}
}
PS: TlbImp.exe
can be found here:
"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin"
, or in
"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7.2 Tools"