1

I've got a c# handler that serves up audio files I've generated using text-to-speech. When the files are written to disk they sound fine, but when I try and play them in a browser (via the handler) using a quicktime plugin it cuts them short at about 2 seconds.

Inside the handler I'm using the following code...

context.Response.ClearContent();
context.Response.ClearHeaders();
context.Response.ContentType = "audio/x-wav";

context.Response.WriteFile(fileName);
context.Response.Flush();

Anyone know what I'm doing wrong?

Chris Pont
  • 789
  • 5
  • 14

1 Answers1

3

You should try writing the file as binary data directly to the OutputStream

context.Response.ClearContent();
context.Response.ClearHeaders();
context.Response.ContentType = "audio/x-wav";
byte[] byteArray = File.ReadAllBytes(fileName);
context.Response.OutputStream.Write(byteArray, 0, byteArray.Length);
Variant
  • 17,279
  • 4
  • 40
  • 65
  • Hi, Thanks for the suggestion. I've just tried this and get the same result. Really strange! Not sure what else to try. – Chris Pont Nov 22 '10 at 12:37
  • 1
    Try calling the handler from a different environment, not a browser with a quicktime plugin. maybe a download manager of some sort. see if you do get the whole file. – Variant Nov 22 '10 at 12:45
  • 1
    It works in VLC player by calling the audio file from the URL. I think the problem is that Quicktime will ask for a seeked number of bytes so maybe I need to include that in the OutputStream.Write call and get the start bytes. – Chris Pont Nov 22 '10 at 15:19
  • Thanks for your answers by the way. It put me in the right direction. – Chris Pont Nov 22 '10 at 15:19