【ASP.NET 进阶】获取MP3文件信息并显示专辑图片
突发奇想,想弄个显示MP3文件信息和专辑图片的小Demo,个人不是大牛,遂百度之,总算搞定,现分享如下。
效果图:

GIF效果图:

主要是依靠2个DLL文件:ID3.dll 和 Interop.Shell32.dll,步骤如下:
1.保存音乐文件到本地
#region 保存音乐文件到本地
string strMp3 = @"~/upload/musics/";
if (!Directory.Exists(Server.MapPath(strMp3)))
{
Directory.CreateDirectory(Server.MapPath(strMp3));
}
strMp3+= fileMp3.FileName ;
if (File.Exists(Server.MapPath(strMp3)))
{
File.Delete(Server.MapPath(strMp3));
}
fileMp3.SaveAs(Server.MapPath(strMp3));
#endregion
2.获取音乐文件信息
#region 获取音乐文件信息
string mp3InfoInterHtml = "";
ShellClass sh = new ShellClass();
Folder dir = sh.NameSpace(Path.GetDirectoryName(Server.MapPath(strMp3)));
FolderItem item = dir.ParseName(Path.GetFileName(Server.MapPath(strMp3)));
mp3InfoInterHtml += "文件名:" + dir.GetDetailsOf(item, )+"<br>";
mp3InfoInterHtml += "文件大小:" + dir.GetDetailsOf(item, ) + "<br>";
mp3InfoInterHtml += "歌曲名:" + dir.GetDetailsOf(item, ) + "<br>";
mp3InfoInterHtml += "歌手:" + dir.GetDetailsOf(item, ) + "<br>";
mp3InfoInterHtml += "专辑:" + dir.GetDetailsOf(item, ) + "<br>";
mp3InfoInterHtml += "时长:" + dir.GetDetailsOf(item, ) + "<br>";
#endregion
3.显示专辑图片
#region 显示专辑图片
string picturePath = @"~/image/play_null_img.png";
if (!Directory.Exists(Server.MapPath(@"~/upload/images/")))
{
Directory.CreateDirectory(Server.MapPath(@"~/upload/images/"));
}
// 加载MP3
ID3Info info = new ID3Info(Server.MapPath(strMp3), true);
System.Drawing.Image image = null;
if (info.ID3v2Info.AttachedPictureFrames.Count > )
{
image = System.Drawing.Image.FromStream(info.ID3v2Info.AttachedPictureFrames.Items[].Data);
picturePath = @"~/upload/images/" +DateTime.Now.ToString("yyyyMMddHHmmss")+ ".png";
if (File.Exists(Server.MapPath(picturePath)))
{
File.Delete(Server.MapPath(picturePath));
}
image.Save(Server.MapPath(picturePath));
}
imgMP3.ImageUrl = picturePath;
dMp3.InnerHtml = mp3InfoInterHtml;
#endregion
4.修改文件上传限制
<httpRuntime maxRequestLength="1048576" executionTimeout="3600" />
源代码:GetMp3Info.zip
参考文章:
http://www.cnblogs.com/08shiyan/p/3579822.html
http://www.codeproject.com/Articles/17890/Do-Anything-With-ID
【ASP.NET 进阶】获取MP3文件信息并显示专辑图片的更多相关文章
- C# 获取 mp3文件信息
C# 获取 mp3文件信息[包括:文件大小.歌曲长度.歌手.专辑] 第一种方式:[代码已验证] // http://bbs.csdn.net/topics/390392612 string fil ...
- C# 获取 mp3文件信息【包括:文件大小、歌曲长度、歌手、专辑】
C# 获取 mp3文件信息[包括:文件大小.歌曲长度.歌手.专辑] 第一种方式:[代码已验证] // http://bbs.csdn.net/topics/390392612 string fil ...
- PHP获取Mp3文件信息
扫描本地MP3文件,获取文件信息
- 实现php获取mp3文件元信息如播放时间歌曲作者等
最近收集到一个php获取mp3文件元信息的类,感觉比较方便.现在分享给大家! 下面是使用方式和测试方式: <?php include_once 'mp3file.class.php'; func ...
- asp.net C#获取程序文件相关信息
代码如下 复制代码 using System.Reflection;using System.Runtime.CompilerServices; //// 有关程序集的常规信息是通过下列// 属性集控 ...
- MP3文件信息修改
MP3文件信息 参考链接:https://www.jianshu.com/p/e368517ec7b9 总结: ID3V1在MP3文件后面;ID3V2在MP3文件前面;现在有些文件是V1的,有些文件是 ...
- C#获取MP3,WMA信息
用于获取MP3内部信息,包括歌曲名,歌手名等…… namespace FileBatchRemaer.domain { /// <summary> /// Mp3信息结构 /// < ...
- MP3文件信息批量更改器
以前(估计是2003年)编写一个MP3文件信息批量更改器MP3TagChanger,现放上来参考.(VB6编码) 使用方法很简单,会Winamp或者千千静听的就懂使用. http://pan.baid ...
- android播放器如何获取音乐文件信息
转http://blog.csdn.net/hellofeiya/article/details/8464356, android自带的音乐播放器中,在获取音乐文件信息的时候是通过扫描得到相关信息的. ...
随机推荐
- HTML5 Wijmo:控制 Wijmo Grid 插件的编辑模式
Wijmo jQuery 插件经常应用于在财务类网站中创建平滑和良好用户体验的交互表格.WijGrid 插件用于显示.排序.分组和编辑数据.今天我们来分享下如何控件WijGrid插件的编辑模式. 在本 ...
- Visual Studio中设置默认VC++路径
菜单"View" -> "Other Windows" -> "Property Manager" 选择对应的配置并修改即可.
- mongodb安装与使用
一.在linux服务器中安装mongodb 1.首先你要有一台安装有linux系统的主机 2.从mongoDB官网下载安装包:http://www.mongodb.org/downloads 3.将下 ...
- Html==>>一些经典
1.CSS overflow 属性 2.<input>标签 <input> 标签用于搜集用户信息. 1 type属性 根据不同的 type 属性值,输入字段拥有很多种形式.可以 ...
- mysql performance_schema/information_schema授权问题
mysql> grant all on performance_schema.* to 'testuser'@'%';ERROR 1044 (42000): Access denied for ...
- 求Mac 的adt插件!
搞了半天原来ADT Mac和win是通用的安装方法也相同! 自己配环境! 下载一个Eclipse,然后安装就行! dns:203.195.223.190 这个DNS可以连上谷歌的服务器(只限学习使用) ...
- CSS3 实现简单轮播图
用css3动画实现图片切换效果,原理还是改变left值.只有最简单的自动播放功能,切换后短时间静止,通过最后的位置克隆第一张图片,实现无缝切换. html结构 <div id="con ...
- ASP.NET控件绑定数据源
DataList/GridView/Repeater DataSet表示数据集,其中包含表,约束和表之间的关系.与现有数据源的交互通过DataAdapter来控制. 源代码示例: SqlDataAda ...
- SharePoint 2013 设置自定义布局页
在SharePoint中,我们经常需要自定义登陆页面.错误页面.拒绝访问等:不知道大家如何操作,以前自己经常在原来页面改或者跳转,其实SharePoint为我们提供了PowerShell命令,来修改这 ...
- 关于停止AsyncTask和Thread的问题
在java的线程中,没有办法停止一个正在运行中的线程.在Android的AsyncTask中也是一样的.如果必须要停止一个线程,可以采用这个线程中设置一个标志位,然后在线程run方法或AsyncTas ...