码迷,mamicode.com
首页 > 其他好文 > 详细

amr转MP3

时间:2016-10-22 09:50:29      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:erro   rect   error   ons   saveas   sharp   har   shell   catch   

using System;
using System.Threading;
using System.IO;
using System.Diagnostics;
using System.Security;

public partial class cowala_201512Chritmas_amrtest : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack) 
    {
      changedPlay.Visible = false;
    }
    }

    protected void Ffmpeg_Click(object sender, EventArgs e)
    {
        if (AmrFileUp.HasFile)
        {
            string key = AmrFileUp.FileName;
            string savepath = Server.MapPath("~/upload/amr/") + key;
            AmrFileUp.SaveAs(savepath);

            string mp3SavePth = 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>");
            }
        }
    }

    public string ConvertToMp3(string pathBefore, string pathLater)
    {
        string c = Server.MapPath("/ffmpeg/") + @"ffmpeg.exe -i " + pathBefore + " " + pathLater;
        string str = RunCmd(c);
        return str;
    }

    /// <summary>
    /// 执行Cmd命令
    /// </summary>
    private string RunCmd(string c)
    {
        try
        {
            ProcessStartInfo info = new ProcessStartInfo("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();
            string outStr = p.StandardOutput.ReadToEnd();
            p.Close();

            return outStr;
        }
        catch (Exception ex)
        {
            return "error" + ex.Message;
        }
    }
}

  

amr转MP3

标签:erro   rect   error   ons   saveas   sharp   har   shell   catch   

原文地址:http://www.cnblogs.com/caohuimingfa/p/5986693.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!