一、音频文件上传和播放
在网上找到一个名叫AspNetPager的第三方控件,将AspNetPager.dll文件引用到项目的Bin中。在网页中可直接调用。引用命名空间 using Telerik.WebControls;
上传
复制代码 代码如下:
protected void Button1_Click(object sender, EventArgs e)
{
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.BaseDirectory + @"SaveFilePath/MBmusic/";//文件上传的路径
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("<script>alert('上传成功!!')</script>");
//Bind();
}
else
{
Response.Write("<script>alert('上传失败!!')</script>");
return;
}
num++;
}
catch { }
}
else
{
Response.Write("<script>alert('空间不足,请申请空间!!')</script>");
return;
}
}
else
{
Response.Write("<script>alert('上传文件格式错误! 文件格式为mp3,wma,wav.rm的视频!')</script>");
return;
}
}
else
{
Response.Write("<script>alert('请选择上传的文件')</script>");
return;
}
}
}
播放
1、在播放页面添加控件Literal1 控件
2、在页面后台添加调用音频播放器代码
复制代码 代码如下:
public static string GetFlashText(string url)
{
string str = @"<object id='MediaPlayer' classid='clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6' height='62' width='406'>
<param name='rate' value='1' />
<param name='balance' value='0' />
<param name='currentPosition' value='0' />
<param name='defaultFrame' value='' />
<param name='playCount' value='1' />
<param name='autoStart' value='-1' />
<param name='currentMarker' value='0' />
<param name='invokeURLs' value='-1' />
<param name='baseURL' value='' />
<param name='volume' value='2' />
<param name='mute' value='0' />
<param name='uiMode' value='full' />
<param name='stretchToFit' value='0' />
<param name='windowlessVideo' value='0' />
<param name='enabled' value='-1' />
<param name='enableContextMenu' value='0' />
<param name='fullScreen' value='0' />
<param name='SAMIStyle' value='' />
<param name='SAMILang' value='' />
<param name='SAMIFilename' value='' />
<param name='captioningID' value='' />
<param name='enableErrorDialogs' value='0' />
<param name='_cx' value='10742' />
<param name='_cy' value='1799' />
<param name='URL' value='"+url+"'/></object>";
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();
}
}
}
在网上找到一个名叫AspNetPager的第三方控件,将AspNetPager.dll文件引用到项目的Bin中。在网页中可直接调用。引用命名空间 using Telerik.WebControls;
上传
复制代码 代码如下:
protected void Button1_Click(object sender, EventArgs e)
{
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.BaseDirectory + @"SaveFilePath/MBmusic/";//文件上传的路径
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("<script>alert('上传成功!!')</script>");
//Bind();
}
else
{
Response.Write("<script>alert('上传失败!!')</script>");
return;
}
num++;
}
catch { }
}
else
{
Response.Write("<script>alert('空间不足,请申请空间!!')</script>");
return;
}
}
else
{
Response.Write("<script>alert('上传文件格式错误! 文件格式为mp3,wma,wav.rm的视频!')</script>");
return;
}
}
else
{
Response.Write("<script>alert('请选择上传的文件')</script>");
return;
}
}
}
播放
1、在播放页面添加控件Literal1 控件
2、在页面后台添加调用音频播放器代码
复制代码 代码如下:
public static string GetFlashText(string url)
{
string str = @"<object id='MediaPlayer' classid='clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6' height='62' width='406'>
<param name='rate' value='1' />
<param name='balance' value='0' />
<param name='currentPosition' value='0' />
<param name='defaultFrame' value='' />
<param name='playCount' value='1' />
<param name='autoStart' value='-1' />
<param name='currentMarker' value='0' />
<param name='invokeURLs' value='-1' />
<param name='baseURL' value='' />
<param name='volume' value='2' />
<param name='mute' value='0' />
<param name='uiMode' value='full' />
<param name='stretchToFit' value='0' />
<param name='windowlessVideo' value='0' />
<param name='enabled' value='-1' />
<param name='enableContextMenu' value='0' />
<param name='fullScreen' value='0' />
<param name='SAMIStyle' value='' />
<param name='SAMILang' value='' />
<param name='SAMIFilename' value='' />
<param name='captioningID' value='' />
<param name='enableErrorDialogs' value='0' />
<param name='_cx' value='10742' />
<param name='_cy' value='1799' />
<param name='URL' value='"+url+"'/></object>";
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();
}
}
}
标签:
音频文件上传,播放
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“Asp.Net 音频文件上传和播放代码”评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。