diff --git a/taglib/mpeg/mpegproperties.cpp b/taglib/mpeg/mpegproperties.cpp index 8507f38d..b9ae8675 100644 --- a/taglib/mpeg/mpegproperties.cpp +++ b/taglib/mpeg/mpegproperties.cpp @@ -205,6 +205,11 @@ void MPEG::Properties::read(File *file) d->bitrate = firstHeader.bitrate(); + // Look for the last MPEG audio frame to calculate the stream length. + + // This actually finds the second last valid frame, since MPEG::Header requires + // the next frame header to check if the frame length is calculated correctly. + long lastFrameOffset = file->lastFrameOffset(); if(lastFrameOffset < 0) { debug("MPEG::Properties::read() -- Could not find an MPEG frame in the stream."); diff --git a/tests/test_mpeg.cpp b/tests/test_mpeg.cpp index 9b972382..455fde2c 100644 --- a/tests/test_mpeg.cpp +++ b/tests/test_mpeg.cpp @@ -93,10 +93,13 @@ public: CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate()); CPPUNIT_ASSERT(!f.audioProperties()->xingHeader()); + // This actually finds the second last valid frame, since MPEG::Header requires + // the next frame header to check if the frame length is calculated correctly. + long last = f.lastFrameOffset(); MPEG::Header lastHeader(&f, last); - while (!lastHeader.isValid()) { + while(!lastHeader.isValid()) { last = f.previousFrameOffset(last); lastHeader = MPEG::Header(&f, last); }