Exemple #1
0
        /// <summary>
        /// 获取标签帧长度
        /// </summary>
        /// <returns></returns>
        private void GetTAGFrameLength()
        {
            //必须为"ID3"否则认为标签不存在
            byte[] mp3Header = MP3Buffer.GetRange(0, 3).ToArray();

            //MP3Stream.Read(mp3Header, 0, mp3Header.Length);

            if (Encoding.ASCII.GetString(mp3Header) != "ID3")
            {
                throw new NotImplementedException("暂只能识别ID3的MP3音频");
            }
            //版本号 ID3V2.3 就记录 3
            byte ver = MP3Buffer[3];
            //副版本号此版本记录为
            byte Revision = MP3Buffer[4];
            //存放标志的字节,这个版本只定义了三位
            byte flag = MP3Buffer[5];

            //标签大小,包括标签头的 10 个字节和所有的标签帧的大小
            byte[] size = MP3Buffer.GetRange(6, 4).ToArray();
            //MP3Stream.Read(size, 0, size.Length);

            MP3Buffer.RemoveRange(0, 10);

            TAGFrameLength = (size[0] & 0x7F) * 0x200000 + (size[1] & 0x7F) * 0x400 + (size[2] & 0x7F) * 0x80
                             + (size[3] & 0x7F);
        }
Exemple #2
0
        /// <summary>
        /// 获取标签帧
        /// </summary>
        /// <returns></returns>
        public byte[] GetTAGFrame()
        {
            GetTAGFrameLength();

            byte[] frameBuffer = MP3Buffer.GetRange(0, TAGFrameLength).ToArray();
            MP3Buffer.RemoveRange(0, TAGFrameLength);
            //MP3Stream.Read(frameBuffer, 0, frameBuffer.Length);
            return(frameBuffer);
        }
Exemple #3
0
        public byte[] GetAudioFrame(out double playTime)
        {
            playTime = 0;
            if (MP3Buffer.Count == 0)
            {
                return(new byte[0]);
            }
            int audioFrameLength = GetAuidoFrameLength(out playTime);

            if (audioFrameLength == 0)
            {
                return(new byte[0]);
            }
            byte[] audioBuffer = MP3Buffer.GetRange(0, audioFrameLength).ToArray();

            //MP3Stream.Read(audioBuffer, 0, audioFrameLength);
            MP3Buffer.RemoveRange(0, audioFrameLength);
            return(audioBuffer);
        }