I´m trying to play wav files with the audio element. This works great when I reference the file directly BUT when I try to stream it via a c# FileStream it stops working. The code below work perfect for Chrome and Opera on PC but I am trying to get it to work on Ipad and Firefox. I am using .net framwork 2.0 I have to use wav.
<audio id="audio" src="www.acme.com/streamer.aspx?music=test.wav" controls preload="auto"></audio> Not working
<audio id="audio" src="test.wav" controls preload="auto"></audio> Working
上游职能如下:
string wavFileName = test.wav;
FileStream soundStream;
long FileSize;
soundStream = new FileStream(@"\netshare" + wavfileName, FileMode.Open, FileAccess.Read, FileShare.Read, 256);
FileSize = soundStream.Length;
byte[] Buffer = new byte[(int)FileSize];
int count = 0;
int offset = 0;
while ((count = soundStream.Read(Buffer, offset,
Buffer.Length)) > 0)
{
Response.OutputStream.Write(Buffer, offset, count);
}
Response.Buffer = true;
Response.Clear();
Response.AddHeader("Content-Type", "audio/wave");
Response.AddHeader("Content-Disposition", "attachment;filename=" + wavfileName);
Response.ContentType = "audio/wave";
Response.BinaryWrite(Buffer);
if (soundStream != null)
{
soundStream.Close();
}
Response.End();
(两次,这是我的第一个职位,希望不要违反任何规则)