【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自带的音乐播放器中,在获取音乐文件信息的时候是通过扫描得到相关信息的. ...
随机推荐
- HDU 2159---FATE---带限制的完全背包
HDU 2159 Description 最近xhd正在玩一款叫做FATE的游戏,为了得到极品装备,xhd在不停的杀怪做任务.久而久之xhd开始对杀怪产生的厌恶感,但又不得不通过杀怪来升完这最后一 ...
- 状态压缩DP---Hie with the Pie
http: //acm.hust.edu.cn/vjudge/contest/view.action?cid=110044#problem/B Description The Pizazz Pizze ...
- 一个web页面的访问的过程
Browers是如何在浩瀚的互联网上找到我们需要的资源呢? 以下将记录这个过程,这个过程是web编程需要需要熟知的. 用户打开浏览器输入目标地址(比如http://www.sina.com),那么接下 ...
- 优先队列(stl)
优先队列是堆排的一种优化,我学习的是使用stl库的堆排. 基本操作有: 1.push将一个元素入队. 2.pop将一个元素出队. 3.top返还值为队头元素. 4.empty判断队列是否为空,为空返回 ...
- lambda 个人学习理解
lambda是简化代码量的写用更简单的方法来写匿名方法 lambda左边是参数,右边是代码块(方法执行语句). 整体运算结果是根据左边参数,执行右边语句,返回右边执行的结果: 匿名方法是简化方法 1. ...
- jQuery对复选框(checkbox)的全选,全不选,反选等的操作
效果截图: HTML代码: <body><ul id="list"> <li><label><input type=" ...
- css权重是什么
css权重是什么? 概述 css Specificity中文一般译为css优先级.css权重.相比"权重","优先级"更好理解,mozilla官方中文文档就翻译 ...
- Configure SSL for SharePoint 2013
http://blogs.msdn.com/b/fabdulwahab/archive/2013/01/21/configure-ssl-for-sharepoint-2013.aspx In thi ...
- R语言学习笔记:简单的回归分析
fitbit <- read.csv("fitbit.csv") date cal step dist floor sit inactive walk run2 ...
- 上传Android代码到Jcenter(解决了字符映射的问题)
请先阅读:http://blog.saymagic.cn/2015/02/16/release-library-to-jcenter.html 最外面的build.gradle // Top-leve ...