一、音频文件上传和播放
在网上找到一个名叫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();
}
}
}
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
暂无评论...
更新日志
2024年11月29日
2024年11月29日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]