문제
I'm trying to convert a WAV file into a WMA file using NAudio. I've managed to get it partly working but the last few seconds of the sound effect is cut off.
WaveFileReader wr = new WaveFileReader(@"C:\mywav.wav");
WmaWriter ww = new WmaWriter(new FileStream(@"C:\mywma.wma",FileMode.Create),new WaveFormat(44100,2),profile);
byte[] buff = null;
int read = 0;
buff=new byte[wr.Length];
read = wr.Read(buff,0,buff.Length);
while ((read > 0))
{
ww.Write(buff,0,read);
read = wr.Read(buff,0,buff.Length);
}
This only partly writes a WMA file and not the whole WAV file that's read in. Alternatively is there a way to convert to WMA without the need for NAudio in C#?
해결책
As discussed in the comments, use a using
block with the writer (and reader actually) so the streams are flushed and closed properly.
제휴하지 않습니다 StackOverflow