예제 #1
0
        /// <summary>
        ///仅使用Windows属性获得歌曲名
        /// </summary>
        /// <param name="path">音乐路径</param>
        /// <param name="type">获得的信息类型</param>
        /// <returns></returns>
        public string GetMusicInfoLite(string path, GetInfoType type)
        {
            string content = null;

            if (!SettingsList.Default.IsAllBass)
            {
                Shell32.Shell sh   = new Shell();
                Folder        dir  = sh.NameSpace(Path.GetDirectoryName(path));
                FolderItem    item = dir.ParseName(Path.GetFileName(path));
                switch (type)
                {
                case GetInfoType.Title:
                {
                    content = dir.GetDetailsOf(item, 21);
                    if (content == "")
                    {
                        content = Path.GetFileNameWithoutExtension(path);
                    }
                    break;
                }                                                                    //标题

                case GetInfoType.FileType: content = Path.GetExtension(path); break; //格式
                }
            }
            return(content);
        }
예제 #2
0
        /// <summary>
        /// 获得DSD音乐信息
        /// </summary>
        /// <param name="path">音乐路径</param>
        /// <param name="type">获得的信息类型</param>
        /// <returns></returns>
        public string GetDSDInfo(string path, GetInfoType type)
        {
            int    stream  = 0;
            string content = null;

            stream = Bass.BASS_StreamCreateFile(path, 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
            switch (type)
            {
            case GetInfoType.Title: content = Bass.BASS_ChannelGetTagsDSDTitle(stream); break;   //标题

            case GetInfoType.Artist: content = Bass.BASS_ChannelGetTagsDSDArtist(stream); break; //艺术家

            case GetInfoType.Length:
            {
                if (Convert.ToInt32(Bass.BASS_ChannelBytes2Seconds(stream, Bass.BASS_ChannelGetLength(stream))) != -1)
                {
                    content = Convert.ToString(Convert.ToInt32(Bass.BASS_ChannelBytes2Seconds(stream, Bass.BASS_ChannelGetLength(stream))));
                }
                else
                {
                    content = "文件损坏";
                    MessageBox.Show("异常:不支持的格式或文件已损坏。\n错误路径:" + path);
                }
                break;        //曲长
            }
            }
            return(content);
        }
예제 #3
0
        /// <summary>
        /// 使用Windows属性获得MP3音乐信息
        /// </summary>
        /// <param name="path">音乐地址</param>
        /// <param name="type">获得的信息类型</param>
        /// <returns></returns>
        public string GetMP3Info(string path, GetInfoType type)
        {
            string content = null;

            if (!SettingsList.Default.IsAllBass)
            {
                Shell32.Shell sh   = new Shell();
                Folder        dir  = sh.NameSpace(Path.GetDirectoryName(path));
                FolderItem    item = dir.ParseName(Path.GetFileName(path));
                switch (type)
                {
                case GetInfoType.Title:
                {
                    content = dir.GetDetailsOf(item, 21);
                    if (content == "")
                    {
                        content = Path.GetFileNameWithoutExtension(path);
                    }
                    break;
                }                                                                     //标题

                case GetInfoType.Artist: content = dir.GetDetailsOf(item, 20); break; //艺术家

                case GetInfoType.Album: content = dir.GetDetailsOf(item, 14); break;  //专辑名

                case GetInfoType.Year: content = dir.GetDetailsOf(item, 15); break;   //日期

                case GetInfoType.Length:
                {
                    try
                    {
                        string hor, min, sec;
                        hor     = dir.GetDetailsOf(item, 27).Substring(0, 2);
                        min     = dir.GetDetailsOf(item, 27).Substring(3, 2);
                        sec     = dir.GetDetailsOf(item, 27).Substring(6, 2);
                        content = Convert.ToString(Convert.ToInt32(hor) * 360 + Convert.ToInt32(min) * 60 + Convert.ToInt32(sec));
                    }        //长度
                    catch (System.ArgumentOutOfRangeException)
                    {
                        MessageBox.Show("获取文件信息失败,可尝试前往设置打开“全部使用Bass库检测音乐信息”");
                    }
                }
                break;

                case GetInfoType.FileType: content = Path.GetExtension(path); break;   //格式
                }
            }
            return(content);
        }
예제 #4
0
        /// <summary>
        /// 获得APE音乐信息
        /// </summary>
        /// <param name="path">音乐路径</param>
        /// <param name="type">获得的信息类型</param>
        /// <returns></returns>
        public string GetAPEInfo(string path, GetInfoType type)
        {
            int    stream  = 0;
            string content = null;

            if (type != GetInfoType.FileType)
            {
                try
                {
                    stream = Bass.BASS_StreamCreateFile(path, 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
                    string[] tags = Bass.BASS_ChannelGetTagsAPE(stream);
                    if (tags != null)
                    {
                        switch (type)
                        {
                        case GetInfoType.Title:
                        {
                            foreach (string x in tags)
                            {
                                if (x.Contains("Title"))
                                {
                                    content = x.Remove(0, 6);
                                    break;
                                }
                                else
                                {
                                    content = null;
                                }
                            }        //标题
                            break;
                        }

                        case GetInfoType.Artist:
                        {
                            foreach (string x in tags)
                            {
                                if (x.Contains("Artist"))
                                {
                                    content = x.Remove(0, 7);
                                    break;
                                }
                                else
                                {
                                    content = null;
                                }
                            }        //艺术家
                            break;
                        }

                        case GetInfoType.Album:
                        {
                            foreach (string x in tags)
                            {
                                if (x.Contains("Album"))
                                {
                                    content = x.Remove(0, 6);
                                    break;
                                }
                                else
                                {
                                    content = null;
                                }
                            }        //专辑名
                            break;
                        }

                        case GetInfoType.Year:
                        {
                            foreach (string x in tags)
                            {
                                if (x.Contains("Year"))
                                {
                                    content = x.Remove(0, 5);
                                    break;
                                }
                                else
                                {
                                    content = null;
                                }
                            }        //年代
                            break;
                        }

                        case GetInfoType.Length:
                        {
                            if (Convert.ToInt32(Bass.BASS_ChannelBytes2Seconds(stream, Bass.BASS_ChannelGetLength(stream))) != -1)
                            {
                                content = Convert.ToString(Convert.ToInt32(Bass.BASS_ChannelBytes2Seconds(stream, Bass.BASS_ChannelGetLength(stream))));                                                                                                           //曲长
                            }
                            else
                            {
                                content = "文件损坏";
                                MessageBox.Show("异常:不支持的格式或文件已损坏。\n错误路径:" + path);
                            }
                            break;
                        }

                        default: break;
                        }
                    }
                }
                catch (System.AccessViolationException)
                {
                    MessageBox.Show("警告!内存溢出!程序将退出");
                    Application.Exit();
                }
            }
            if (type == GetInfoType.FileType)
            {
                content = Path.GetExtension(path);                              //格式
            }
            if (type == GetInfoType.Title && content == null)
            {
                content = Path.GetFileNameWithoutExtension(path);
            }
            return(content);
        }