|
usingSystem;
usingSystem.Threading;
usingSystem.IO;
usingSystem.Diagnostics;
usingSystem.Security;
publicpartialclasscowala_201512Chritmas_amrtest : System.Web.UI.Page
{
protectedvoidPage_Load(objectsender, EventArgs e)
{
if(!IsPostBack)
{
changedPlay.Visible =false;
}
}
protectedvoidFfmpeg_Click(objectsender, EventArgs e)
{
if(AmrFileUp.HasFile)
{
stringkey = AmrFileUp.FileName;
stringsavepath = Server.MapPath("~/upload/amr/") + key;
AmrFileUp.SaveAs(savepath);
stringmp3SavePth = Server.MapPath("~/upload/mp3/") + key.Split('.')[0].ToString() +".mp3";
if(!string.IsNullOrEmpty(ConvertToMp3(savepath, mp3SavePth)))
{
changedPlay.Visible =true;
changedPlay.Attributes.Add("src","upload/mp3/"+ key.Split('.')[0].ToString() +".mp3");
Response.Write("<script>alert('轉換成功!');</script>");
}
}
}
publicstringConvertToMp3(stringpathBefore,stringpathLater)
{
stringc = Server.MapPath("/ffmpeg/") +@"ffmpeg.exe -i "+ pathBefore +" "+ pathLater;
stringstr = RunCmd(c);
returnstr;
}
/// <summary>
/// 執行Cmd命令
/// </summary>
privatestringRunCmd(stringc)
{
try
{
ProcessStartInfo info =newProcessStartInfo("cmd.exe");
info.RedirectStandardOutput =false;
info.UseShellExecute =false;
Process p = Process.Start(info);
p.StartInfo.UseShellExecute =false;
p.StartInfo.RedirectStandardInput =true;
p.StartInfo.RedirectStandardOutput =true;
p.StartInfo.RedirectStandardError =true;
p.Start();
p.StandardInput.WriteLine(c);
p.StandardInput.AutoFlush =true;
Thread.Sleep(1000);
p.StandardInput.WriteLine("exit");
p.WaitForExit();
stringoutStr = p.StandardOutput.ReadToEnd();
p.Close();
returnoutStr;
}
catch(Exception ex)
{
return"error"+ ex.Message;
}
}
}
|