calculate song length more accurately

git-svn-id: https://svn.musicpd.org/mpd/trunk@444 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
Warren Dukes 2004-03-24 02:26:57 +00:00
parent 7479bfacbb
commit 0977ab5b4e

View File

@ -343,11 +343,18 @@ int decodeFirstFrame(mp3DecodeData * data) {
} }
} }
else { else {
size_t offset = data->currentOffset;
mad_timer_t duration = data->frame.header.duration; mad_timer_t duration = data->frame.header.duration;
float frameTime = ((float)mad_timer_count(duration, float frameTime = ((float)mad_timer_count(duration,
MAD_UNITS_MILLISECONDS))/1000; MAD_UNITS_MILLISECONDS))/1000;
fstat(fileno(data->fp),&filestat); fstat(fileno(data->fp),&filestat);
data->totalTime = (filestat.st_size*8.0)/ if(data->stream.this_frame!=NULL) {
offset-= data->stream.bufend-data->stream.this_frame;
}
else {
offset-= data->stream.bufend-data->stream.buffer;
}
data->totalTime = ((filestat.st_size-offset)*8.0)/
(data->frame).header.bitrate; (data->frame).header.bitrate;
data->maxFrames = data->totalTime/frameTime+FRAMES_CUSHION; data->maxFrames = data->totalTime/frameTime+FRAMES_CUSHION;
} }