求助 错误:并非所有的代码路径都返回值

u010137280 2013-04-23 10:31:18
PublicMethod.ChangeFilePhy(string, string, string)”: 并非所有的代码路径都返回值并非所有的代码路径都返回值

出错的是这句public string ChangeFilePhy(string fileName, string playFile, string imgFile)

看到这句话 我第一反应就是 我这三个string fileName, string playFile, string imgFile没有返回,但是我的确有写返回,所以我不知道错在哪了,请各位指点我一下 附上代码
Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
// 扩展名定义
string[] strArrFfmpeg = new string[] { "asf", "avi", "mpg", "3gp", "mov" };
string[] strArrMencoder = new string[] { "wmv", "rm", "rmvb" };
protected void Page_Load(object sender, EventArgs e)
{
}
//
protected void btnUpload_Click(object sender, EventArgs e)
{
string upFileName = "";
if (this.FileUpload1.HasFile)
{
string fileName = PublicMethod.GetFileName(this.FileUpload1.FileName);// GetFileName();
if ((string)Session["file"] == fileName)
{
return;
}
upFileName = Server.MapPath(PublicMethod.upFile + fileName);
this.FileUpload1.SaveAs(upFileName);
string saveName = DateTime.Now.ToString("yyyyMMddHHmmssffff");
string playFile = Server.MapPath(PublicMethod.playFile + saveName);
string imgFile = Server.MapPath(PublicMethod.imgFile + saveName);
//System.IO.File.Copy(Server.MapPath(PublicMethod.playFile + "00000002.jpg"), Server.MapPath(PublicMethod.imgFile+"aa.jpg"));
PublicMethod pm = new PublicMethod();
string m_strExtension = PublicMethod.GetExtension(this.FileUpload1.PostedFile.FileName).ToLower();
if (m_strExtension == "flv")
{//直接拷贝到播放文件夹下
System.IO.File.Copy(upFileName, playFile + ".flv");
pm.CatchImg(upFileName, imgFile);
}
string Extension = CheckExtension(m_strExtension);
if (Extension == "ffmpeg")
{
pm.ChangeFilePhy(upFileName,playFile,imgFile);
}
/* else if (Extension == "mencoder")
{
pm.MChangeFilePhy(upFileName, playFile, imgFile);
}
InsertData(this.txtTitle.Text, fileName, saveName);*/
Session["file"] = fileName;
}
}
//
private string CheckExtension(string extension)
{
string m_strReturn = "";
foreach (string var in this.strArrFfmpeg)
{
if (var == extension)
{
m_strReturn = "ffmpeg"; break;
}
}
/* if (m_strReturn == "")
{
foreach (string var in strArrMencoder)
{
if (var == extension)
{
m_strReturn = "mencoder"; break;
}
}
}*/
return m_strReturn;
}
}


PublicMethod.cs

using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Diagnostics;

/// <summary>
///PublicMethod 的摘要说明
/// </summary>
public class PublicMethod
{
public PublicMethod()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
public static string ffmpegtool = ConfigurationManager.AppSettings["ffmpeg"];
public static string mencodertool = ConfigurationManager.AppSettings["mencoder"];
public static string mplayertool = ConfigurationManager.AppSettings["mplayer"];
public static string upFile = ConfigurationManager.AppSettings["upfile"] + "/";
public static string imgFile = ConfigurationManager.AppSettings["imgfile"] + "/";
public static string playFile = ConfigurationManager.AppSettings["playfile"] + "/";
//文件图片大小
public static string sizeOfImg = ConfigurationManager.AppSettings["CatchFlvImgSize"];
//文件大小
public static string widthOfFile = ConfigurationManager.AppSettings["widthSize"];
public static string heightOfFile = ConfigurationManager.AppSettings["heightSize"];
// // //获取文件的名字
public static string GetFileName(string fileName)
{
int i = fileName.LastIndexOf("\\") + 1;
string Name = fileName.Substring(i);
return Name;
}
//获取文件扩展名
public static string GetExtension(string fileName)
{
int i = fileName.LastIndexOf(".") + 1;
string Name = fileName.Substring(i);
return Name;
}
//
#region //运行FFMpeg的视频解码,(这里是绝对路径)
/// <summary>
/// 转换文件并保存在指定文件夹下面(这里是绝对路径)
/// </summary>
/// <param name="fileName">上传视频文件的路径(原文件)</param>
/// <param name="playFile">转换后的文件的路径(网络播放文件)</param>
/// <param name="imgFile">从视频文件中抓取的图片路径</param>
/// <returns>成功:返回图片虚拟地址; 失败:返回空字符串</returns>
public string ChangeFilePhy(string fileName, string playFile, string imgFile)
{
string ffmpeg = System.Web.HttpContext.Current.Server.MapPath(PublicMethod.ffmpegtool);
if ((!System.IO.File.Exists(ffmpeg)) || (!System.IO.File.Exists(fileName)))
{
return "";
}
//获得图片和(.flv)文件相对路径/最后存储到数据库的路径,如:/Web/User1/00001.jpg
// string flv_file = System.IO.Path.ChangeExtension(playFile, ".flv");

//截图的尺寸大小,配置在Web.Config中,如:<add key="CatchFlvImgSize" value="240x180" />


string filename = TransferVedio(upFile, playFile);

string smallpic = CatchImg(upFile, imgFile);


}

public string TransferVedio(string upFileName, string playFile)
{
string ffmpeg = System.Web.HttpContext.Current.Server.MapPath(PublicMethod.ffmpegtool);
string flv_file = System.IO.Path.ChangeExtension(playFile, ".flv");

//截图的尺寸大小,配置在Web.Config中,如:<add key="CatchFlvImgSize" value="240x180" />
//string FlvImgSize = VedioConvert.sizeOfImg;

Process p = new Process();//建立外部调用线程
p.StartInfo.FileName = ffmpeg;//要调用外部程序的绝对路径
p.StartInfo.Arguments = " -i " + "\"" + upFileName + "\"" + " -ab 56 -ar 22050 -b 500 -r 15 -s " + widthOfFile + "x" + heightOfFile + " " + "\"" + flv_file + "\"";

p.StartInfo.UseShellExecute = false;//不使用操作系统外壳程序启动线程(一定为FALSE,详细的请看MSDN)
p.StartInfo.RedirectStandardError = true;//把外部程序错误输出写到StandardError流中(这个一定要注意,FFMPEG的所有输出信息,都为错误输出流,用StandardOutput是捕获不到任何消息的...这是我耗费了2个多月得出来的经验...mencoder就是用standardOutput来捕获的)
p.StartInfo.CreateNoWindow = true;//不创建进程窗口
//p.ErrorDataReceived += new DataReceivedEventHandler(Output);//外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
p.Start();//启动线程
p.BeginErrorReadLine();//开始异步读取
p.WaitForExit();//阻塞等待进程结束
p.Close();//关闭进程
p.Dispose();//释放资源


if (System.IO.File.Exists(flv_file) && new FileInfo(flv_file).Length > 0)
{
return flv_file.Substring(flv_file.LastIndexOf("\\") + 1);
}
else
{
return "";
}


}

public string CatchImg(string fileName, string imgFile)
{
string ffmpeg = System.Web.HttpContext.Current.Server.MapPath(PublicMethod.ffmpegtool);
string flv_img = imgFile + ".jpg";
string FlvImgSize = VedioConvert.sizeOfImg;


Process p = new Process();//建立外部调用线程
p.StartInfo.FileName = ffmpeg;//要调用外部程序的绝对路径
p.StartInfo.Arguments = @"-i " + "\"" + fileName + "\"" + " -y -f image2 -ss 08.010 -t 0.001 -s 352x240 " + "\"" + flv_img + "\"";

p.StartInfo.UseShellExecute = false;//不使用操作系统外壳程序启动线程(一定为FALSE,详细的请看MSDN)
p.StartInfo.RedirectStandardError = true;//把外部程序错误输出写到StandardError流中(这个一定要注意,FFMPEG的所有输出信息,都为错误输出流,用StandardOutput是捕获不到任何消息的...这是我耗费了2个多月得出来的经验...mencoder就是用standardOutput来捕获的)
p.StartInfo.CreateNoWindow = true;//不创建进程窗口
//p.ErrorDataReceived += new DataReceivedEventHandler(Output);//外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
p.Start();//启动线程
p.BeginErrorReadLine();//开始异步读取
p.WaitForExit();//阻塞等待进程结束
p.Close();//关闭进程
p.Dispose();//释放资源


if (System.IO.File.Exists(flv_img) && new FileInfo(flv_img).Length > 0)
{
return flv_img.Substring(flv_img.LastIndexOf("\\") + 1);
}
else
{
return "";
}


}



#endregion

}


...全文
184 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
threenewbee 2013-04-23
  • 打赏
  • 举报
回复
引用 2 楼 u010137280 的回复:
引用 1 楼 caozhy 的回复:public string ChangeFilePhy(string fileName, string playFile, string imgFile) { string ffmpeg = System.Web.HttpContext.Current.Server.MapPath(PublicMethod.……
什么后面都有返回值,后面没有了都。
u010137280 2013-04-23
  • 打赏
  • 举报
回复
引用 1 楼 caozhy 的回复:
public string ChangeFilePhy(string fileName, string playFile, string imgFile) { string ffmpeg = System.Web.HttpContext.Current.Server.MapPath(PublicMethod.ffmpegtool); ……
你的意思是说 在 string filename = TransferVedio(upFile, playFile); string smallpic = CatchImg(upFile, imgFile); 后面 加return吗 可是我这两个后面都是有返回值的 这样的话还需要在你说的那里写return吗
threenewbee 2013-04-23
  • 打赏
  • 举报
回复
public string ChangeFilePhy(string fileName, string playFile, string imgFile) { string ffmpeg = System.Web.HttpContext.Current.Server.MapPath(PublicMethod.ffmpegtool); if ((!System.IO.File.Exists(ffmpeg)) || (!System.IO.File.Exists(fileName))) { return""; } //获得图片和(.flv)文件相对路径/最后存储到数据库的路径,如:/Web/User1/00001.jpg // string flv_file = System.IO.Path.ChangeExtension(playFile, ".flv"); //截图的尺寸大小,配置在Web.Config中,如:<add key="CatchFlvImgSize" value="240x180" /> string filename = TransferVedio(upFile, playFile); string smallpic = CatchImg(upFile, imgFile); return filename; }

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧