Tôi muốn nhận thông tin về thời lượng cho một tệp mp3 từ xa khi bắt đầu tải xuống. Tôi có thể nhận được các khung hình lúc đầu nhưng không biết phải đọc, Xing hoặc VBRi.Làm thế nào để tính toán BitRate cho một VBR mp3 mà không cần tải xuống toàn bộ tệp?
Làm cách nào để có được thông tin này bằng cách đọc các thẻ?
MemoryStream ms = new MemoryStream();
waveOut.Play();
long offset = from;
ms.Position = 0;
byte[] decBuffer = new byte[50 * 1024];
while (true)
{
if (paused)
{
waveOut.Stop();
bwProvider.ClearBuffer();
break;
}
lock (LockObj)
{
byte[] readed = Helper.ReadStreamPartially(localStream, offset, 100 * 1024, orders);
if (readed == null)
continue;
ms = new MemoryStream(readed);
}
Mp3Frame frame;
try
{
frame = Mp3Frame.LoadFromStream(ms);
}
catch
{
continue;
}
if (frame == null)
continue;
int decompressed = decompressor.DecompressFrame(frame, decBuffer, 0);
bwProvider.AddSamples(decBuffer, 0, decompressed);
if (Helper.IsBufferNearlyFull(bwProvider))
Thread.Sleep(500);
offset += ms.Position;
}
http://stackoverflow.com/q/9046492/1070452 – Plutonix
Có thể điều này sẽ giúp bạn - https://www.mp3-tech.org/programmer/frame_header.html và http://mpgedit.org/ mpgedit/mpeg_format/mpeghdr.htm –
Có một cái nhìn tại đây http://stackoverflow.com/questions/6196011/how-to-read-xingheaders-and-vbriheaders-from-mp3-files-using-taglib-sharp –