C#处理Android Audio and Video

Video Converter for .NET (C#) FFMpeg wrapper

http://www.nrecosite.com/video_converter_net.aspx

 

Document: http://www.nrecosite.com/doc/NReco.VideoConverter/

 

Nuget: https://www.nuget.org/packages/NReco.VideoConverter/

Install-Package NReco.VideoConverter

 

获取MP3声音长度

http://stackoverflow.com/questions/13722501/easiest-way-to-get-mp3-duration-and-size

方法1: 通过NAudio

Mp3FileReader reader = new Mp3FileReader("filename.mp3");
TimeSpan duration = reader.TotalTime;

方法2: 通过Shell32 DLL

public class Mp3Service
    {
        /// <summary>
        /// 根据mp3文件的绝对路径和属性名称获得属性值
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="attributeName">如:播放时间、文件大小、比特率</param>
        /// <returns></returns>
        public static string GetFileAttribute(string filePath, string attributeName)
        {
            //TagLib.File file = new AudioFile(filePath);

            string attributeVal = "";
            List<string> fileInfoArr = GetMp3FileDetailInfo(filePath);
            if (System.Web.HttpContext.Current != null)
            {
                System.Web.HttpContext.Current.Trace.Write("AuduioFileInfo", JsonConvert.SerializeObject(fileInfoArr));
            }
            switch (attributeName)
            {
                case "播放时间":
                    if (fileInfoArr.Count > 28)
                        attributeVal = fileInfoArr[28];
                    break;
                case "文件大小":
                    if (fileInfoArr.Count > 2)
                        attributeVal = fileInfoArr[2];
                    break;
                case "比特率":
                    if (fileInfoArr.Count > 29)
                        attributeVal = fileInfoArr[29];
                    break;

            }
            return attributeVal;
        }

        /// <summary>
        /// 获得mp3文件的详细信息
        /// </summary>
        /// <param name="strPath"></param>
        /// <returns></returns>
        public static List<string> GetMp3FileDetailInfo(string strPath)
        {
            List<string> fileInfoArr = new List<string>();

            Shell32.Shell sh = new Shell32.Shell();
            Folder dir = sh.NameSpace(Path.GetDirectoryName(strPath));
            FolderItem item = dir.ParseName(Path.GetFileName(strPath));
            for (int i = -1; i < 50; i++)
            {
                // 0检索项的名称。
                // 1检索项的大小。
                // 2检索条目的类型。
                // 3检索项最后修改日期和时间。
                // 4检索项的属性。
                // -1项检索信息提示信息。
                fileInfoArr.Add(dir.GetDetailsOf(item, i));
            }
            return fileInfoArr;
        }
    }
posted @ 2015-02-28 15:17  NiuSys  阅读(660)  评论(0编辑  收藏  举报