public static void TestRead_FixedBitrate() { using (MemoryStream stream = new MemoryStream(mp3FixedBitrate)) { MP3Header header = new MP3Header(); header.Read(stream, 4341760); Debug.Assert(header.BitRate == 128); Debug.Assert(header.FileSize == 4341760); Debug.Assert(header.HasVBR == false); Debug.Assert(Math.Abs(header.LengthInSeconds - 271.36) < 0.01); Debug.Assert(header.Mode == MP3Header.Modes.JointStereo); } }
public static void TestRead_VariableBitrate() { using (MemoryStream stream = new MemoryStream(mp3VBR)) { MP3Header header = new MP3Header(); header.Read(stream, 1171900); Debug.Assert(header.BitRate == 185); Debug.Assert(header.FileSize == 1171900); Debug.Assert(header.HasVBR == true); Debug.Assert(header.LengthInSeconds == 50.67675675675676); Debug.Assert(header.Mode == MP3Header.Modes.JointStereo); } }
public static int ReadBitrate(Stream stream, long dataLength) { MP3Header h = new MP3Header(); h.Read(stream, dataLength); if (h.IsValidHeader()) { return(h.BitRate); } else { return(-1); } }
public static int LoadFileLengthFromMp3(string file, MpegDataSize sizeProvider, MpegSkipBytes skipBytes) { using (Stream stream = VirtualDrive.OpenInStream(file)) { MP3Header mp3hdr = new MP3Header(); FileInfo fileInfo = new FileInfo(file); stream.Seek(skipBytes(fileInfo), SeekOrigin.Current); bool boolIsMP3 = mp3hdr.Read(stream, sizeProvider(fileInfo)); if (boolIsMP3) { return((int)Math.Round(mp3hdr.LengthInSeconds)); } else { return(0); } } }