I have a 800mb wma file that I need to split into multiple files programmatically on the fly by specifying a start and end point in bytes.
I tried doing it by reading a file into a file stream and then writing it back out changing the start position like this.
Stream GetAudioPiece(Guid key, int start, int stop)
{
FileStream Book = new FileStream("d:\\war_peace.
wma", FileMode.Open, FileAccess.Read);
int partSize = stop - start;
FileStream Part = new FileStream("d:\\war_part.w
ma", FileMode.Create, FileAccess.Write);
byte[] buffer = new byte[partSize];
int data = 0;
Book.Position = (long)start;
data = Book.Read(buffer, 0, partSize);
Part.Write(buffer, 0, data);
Part.Close();
FileStream retValue = File.OpenRead("d:\\war_par
t.wma");
return retValue;
}
This didn't work. I read somewhere that is because WMA files have headers that are required. So, the question is: How do I read the header from the original file and attach it to the piece I want to stream back?
Start Free Trial