I have a problem with MediaFoundationEncoder
I need to record from input device file in AAC format, I write the following code:
private Timer timer;
private static IWaveIn _waveIn;
private static IWaveProvider _provider;
public void StartRecorder()
{
_waveIn = new WaveInEvent
{
WaveFormat = new WaveFormat(8000, 1)
};
_provider = new WaveInProvider(_waveIn);
_waveIn.DataAvailable += OnDataAvailable;
_waveIn.StartRecording();
//for testing purpose write only first 5 seconds.
timer = new Timer(5000);
timer.Elapsed += (sender, args) => Stop();
timer.Start();
}
private void Stop()
{
timer.Stop();
_waveIn.StopRecording();
_waveIn.Dispose();
_waveIn = null;
var outputFilename = String.Format("D:\\{0:yyy-mm-dd HH-mm-ss}.aac", DateTime.Now);
MediaFoundationEncoder.EncodeToAac(_provider, outputFilename);
_provider = null;
}
Also I tried to use MediaFoundationEncoder.EncodeToWma - BUT the file size continued to grow even after stopping the recording and disposed _waveIn. Timeline in file is corrrect, something writes to file trash bytes.
P.S. Im using the lastet build of NAudio (1.7).