[WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class Player1 : IHttpHandler {
public void ProcessRequest(HttpContext context) { if (context.Request.QueryString["Title"] != string.Empty) { string filename = context.Request.QueryString["Title"] + ".mp3"; string path = context.Server.MapPath("audio"); string file = path + "\\" + filename; if (System.IO.File.Exists(file)) { FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read); context.Response.Buffer = true; context.Response.Clear(); context.Response.ClearContent(); context.Response.ClearHeaders(); context.Response.AddHeader("content-disposition", "attachement; filename=" + filename); context.Response.AddHeader("content-length", fs.Length.ToString()); context.Response.ContentType = "audio/mpeg"; byte[] bytes = new byte[fs.Length]; int bytesToRead = (int)fs.Length; int bytesRead = 0; while (bytesToRead > 0) { int n = fs.Read(bytes, bytesRead, bytesToRead); if (n == 0) break; bytesRead += n; bytesToRead -= n; } bytesToRead = bytes.Length; context.Response.OutputStream.Write(bytes, 0, bytes.Length); } } context.Response.End(); }
public bool IsReusable { get { return false; } } }