naudio / NAudio

Audio and MIDI library for .NET
MIT License
5.5k stars 1.1k forks source link

MediaFoundationReader doesnt work with opus format #1123

Open Mrgaton opened 7 months ago

Mrgaton commented 7 months ago

My code

MediaFoundationReader reader = new MediaFoundationReader(videoPath);

BufferedWaveProvider bufferedWaveProvider = new BufferedWaveProvider(reader.WaveFormat);
bufferedWaveProvider.BufferDuration = TimeSpan.FromMilliseconds(audioBufferLengh * 4);
bufferedWaveProvider.DiscardOnBufferOverflow = true;
bufferedWaveProvider.ReadFully = true;

WaveOut player = new WaveOut();

player.Init(bufferedWaveProvider);

player.Play();

the exception:


Excepcion no controlada: System.Runtime.InteropServices.COMException: No se encontro ninguna transformacion adecuada para codificar o descodificar el contenido. (Excepcion de HRESULT: 0xC00D5212)
   en NAudio.MediaFoundation.IMFSourceReader.SetCurrentMediaType(Int32 dwStreamIndex, IntPtr pdwReserved, IMFMediaType pMediaType)
   en NAudio.Wave.MediaFoundationReader.CreateReader(MediaFoundationReaderSettings settings)
   en NAudio.Wave.MediaFoundationReader.Init(MediaFoundationReaderSettings initialSettings)
   en NAudio.Wave.MediaFoundationReader..ctor(String file)
   en AsciiPlayer.Program.Main(String[] arg) en AsciiPlayer\Program.cs:linea 160

the video:

https://github.com/naudio/NAudio/assets/68958481/4f273ff5-9576-4693-a44b-86b17ed998fe

markheath commented 7 months ago

MediaFoundationReader relies on the codecs installed in Windows, so if your version of Windows can't play the file in Windows Media Player then its likely that MediaFoundationPlayer also won't be able to play it