using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.IO;

namespace SilverTunes_Web
{
    /// <summary>
    /// Summary description for $codebehindclassname$
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class GetSong : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            var file = context.Request.Params["path"];
            if (!Path.IsPathRooted(file))
            {
                file = context.Server.MapPath(file);
            }
            else if (!MediaLibrary.IsLocalServer)
            {
                return;
            }

            context.Response.TransmitFile(file);

            var ext = Path.GetExtension(file);
            if (ext == ".mp3")
            {
                context.Response.ContentType = "audio/mpeg";
            }
            else if (ext == ".wma")
            {
                context.Response.ContentType = "audio/x-ms-wma";
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
