一、音频文件上传和播放
在网上找到一个名叫AspNetPager的第三方控件,将AspNetPager.dll文件引用到项目的Bin中。在网页中可直接调用。引用命名空间 using Telerik.WebControls;
>>上传
protected void Button1_Click(ob
{
foreach (UploadedFile file in RadUploadContext.Current.UploadedFiles)
{
if (file.FileName != null &&file.FileName != "")
{
string strTime = memberid.ToString() + "-" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Millisecond.ToString();
string namefile = file.FileName;//获取文件原来的名字
string namelast = namefile.Substring(namefile.LastIndexOf("."));//获取文件的后缀名LastIndexOf()-返回括号内字符的所在位置
string FilePath = System.AppDomain.CurrentDomain.ba
System.IO.FileInfo fi = new System.IO.FileInfo(file.FileName);
if (fi.Extension.ToLower() == ".mp3" || fi.Extension.ToLower() == ".wma" || fi.Extension.ToLower() == ".rm" || fi.Extension.ToLower() == ".wav")
{
string name = strTime + namelast;//文件最后保存的名字
mv = "http://www.cnblogs.com/SaveFilePath/MBmusic/" + name;
Filesizes = int.Parse(file.ContentLength.ToString());
string path = FilePath + name;
if (File.Exists(path) == false)
{
file.SaveAs(FilePath + name);
mf.MF_Path = mv;
//mf.MF_Path = mv;
}
else if (File.Exists(path) == true)
{
name = strTime + "(" + tt + ")" + namelast;
file.SaveAs(FilePath + name);
mv = "http://www.cnblogs.com/SaveFilePath/MBmusic/" + name;
mf.MF_Path = mv;
//mf.MF_Path = mv;
}
if (RemainByteSize >= Filesizes)
{
try
{
if (addnum >0 &&udpsize >0)
{
//Response.Write("alert('上传成功!!')");
//Bind();
}
else
{
Response.Write("alert('上传失败!!')");
return;
}
num++;
}
catch { }
}
else
{
Response.Write("alert('空间不足,请申请空间!!')");
return;
}
}
else
{
Response.Write("alert('上传文件格式错误! 文件格式为mp3wmawav.rm的视频!')");
return;
}
}
else
{
Response.Write("alert('请选择上传的文件')");
return;
}
}
}
>>播放
1、在播放页面添加控件Literal1 控件
2、在页面后台添加调用音频播放器代码
public static string GetFlashText(string url){
string str = @"
";
return str;
}
3、调用GetFlashText()方法
public void BindMusic()
{
if (mfid != 0)
{
DataSet dst = mf.Search(mfid);
if (dst != null &&dst.Tables[0].Rows.Count >0)
{
string url = dst.Tables[0].Rows[0]["MF_Path"].ToString();
string[] strs = url.Split(new char[] { '/' });
string mvname = strs[strs.Length - 1];
string url1 = "SaveFilePath/MBmv/" + mvname;
Literal1.Text = GetFlashText(url);//Literal1调用方法播放音频
Label1.Text = dst.Tables[0].Rows[0]["MF_FileName"].ToString();
//txt_FileName.Text = dst.Tables[0].Rows[0]["MF_FileName"].ToString();
//txt_introduction.Text = dst.Tables[0].Rows[0]["MF_Introduction"].ToString();
}
}
}