Ejemplo n.º 1
0
        /// <summary>
        /// Reads tags from a File.
        /// </summary>
        public static TagReader Read(string FileName)
        {
            Bass.Init();

            var h = Bass.CreateStream(FileName, Flags: BassFlags.Prescan);

            TagReader result = null;

            if (h != 0)
            {
                result = Read(h);

                Bass.StreamFree(h);
            }
            else
            {
                h = Bass.MusicLoad(FileName, Flags: BassFlags.Prescan);

                if (h != 0)
                {
                    result = Read(h);

                    Bass.MusicFree(h);
                }
            }

            if (!string.IsNullOrWhiteSpace(result?.Title))
                result.Title = System.IO.Path.GetFileNameWithoutExtension(FileName);

            return result;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Reads tags from a <paramref name="Channel"/>.
        /// </summary>
        public static TagReader Read(int Channel)
        {
            var result = new TagReader();
            var info = Bass.ChannelGetInfo(Channel);
            
            switch (info.ChannelType)
            {
                case ChannelType.MP1:
                case ChannelType.MP2:
                case ChannelType.MP3:
                    if (result.ReadID3v2(Channel)) { }

                    else if (result.ReadID3v1(Channel)) { }

                    else if (result.ReadApe(Channel)) { }

                    else if (result.ReadBWF(Channel)) { }
                    break;

                case ChannelType.OGG:
                    if (result.ReadOgg(Channel)) { }

                    else if (result.ReadApe(Channel)) { }
                    break;

                case ChannelType.MP4:
                case ChannelType.AAC:
                    if (result.ReadMp4(Channel)) { }

                    else if (result.ReadID3v2(Channel)) { }

                    else if (result.ReadApe(Channel)) { }

                    else if (result.ReadOgg(Channel)) { }
                    break;

                case ChannelType.Wave:
                case ChannelType.WavePCM:
                case ChannelType.WaveFloat:
                    if (result.ReadRiffInfo(Channel)) { }

                    else if (result.ReadBWF(Channel)) { }

                    else if (result.ReadID3v2(Channel)) { }
                    break;

                case ChannelType.DSD:
                    result.Title = Marshal.PtrToStringAnsi(Bass.ChannelGetTags(Channel, TagType.DSDTitle));
                    result.Artist = Marshal.PtrToStringAnsi(Bass.ChannelGetTags(Channel, TagType.DSDArtist));
                    break;

                case ChannelType.MOD:
                    result.Title = Marshal.PtrToStringAnsi(Bass.ChannelGetTags(Channel, TagType.MusicName));
                    result.Artist = Marshal.PtrToStringAnsi(Bass.ChannelGetTags(Channel, TagType.MusicAuth));
                    result.Comment = Marshal.PtrToStringAnsi(Bass.ChannelGetTags(Channel, TagType.MusicMessage));
                    break;

                default:
                    if (result.ReadApe(Channel)) { }

                    else if (result.ReadOgg(Channel)) { }

                    else if (result.ReadID3v2(Channel)) { }

                    else if (result.ReadID3v1(Channel)) { }
                    break;
            }

            if (string.IsNullOrWhiteSpace(result.Lyrics))
            {
                var ptr = Bass.ChannelGetTags(Channel, TagType.Lyrics3v2);

                if (ptr != IntPtr.Zero)
                    result.Lyrics = Marshal.PtrToStringAnsi(ptr);
            }

            return result;
        }