<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.5730.13" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=763415815-03062011><FONT face=Arial size=2>Hi, one of the
requirements we have here is to detect if an audio file is valid or not. E.g: if
an EXE file was renamed to .MP3, we need to know that it's bad! I've tested
this on several of the supported file formats and the behaviour of TagLib
seems to vary. Sometimes FileRef.IsNull() is true, sometimes I have to check the
Tag() pointer and even sometimes I need to check the audioProperties() pointer.
However, with MP3 files, the results from a valid MP3 file without any tags
(ID3v1, ID3v2 & APE) and an invalid MP3 file are the same so I can't detect
if it's truely a valid MP3 file or not. Even the audioProperties() gives me
results.</FONT></SPAN></DIV>
<DIV><SPAN class=763415815-03062011><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=763415815-03062011><FONT face=Arial size=2>I have found a way
around this by a small modification to 'mpegfile.cpp' in
MPEG::File::read:</FONT></SPAN></DIV>
<DIV><SPAN class=763415815-03062011><FONT face=Arial size=2></FONT><FONT
face=Arial size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=763415815-03062011>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 9.5pt; FONT-FAMILY: Consolas; mso-bidi-font-family: Consolas"><SPAN
style="mso-spacerun: yes"> </SPAN><SPAN style="COLOR: green">//if no tag
was found at all, make sure this is a valid MP3 file by checking the MP3
header</SPAN><?xml:namespace prefix = o ns =
"urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 9.5pt; FONT-FAMILY: Consolas; mso-bidi-font-family: Consolas"><SPAN
style="mso-spacerun: yes"> </SPAN><SPAN style="COLOR: blue">if</SPAN>
(!d->hasID3v2 && ! d->hasID3v1 && !d->hasAPE)
{<o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 9.5pt; FONT-FAMILY: Consolas; mso-bidi-font-family: Consolas"><SPAN
style="mso-tab-count: 1"> </SPAN><SPAN
style="COLOR: green">//goto the beginning of the file and read the
header</SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 9.5pt; FONT-FAMILY: Consolas; mso-bidi-font-family: Consolas"><SPAN
style="mso-tab-count: 1">
</SPAN>seek(0);<o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 9.5pt; FONT-FAMILY: Consolas; mso-bidi-font-family: Consolas"><SPAN
style="mso-tab-count: 1">
</SPAN>MPEG::Header header(readBlock(4));<o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 9.5pt; FONT-FAMILY: Consolas; mso-bidi-font-family: Consolas"><SPAN
style="mso-tab-count: 1">
</SPAN>setValid(header.isValid());<o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 9.5pt; FONT-FAMILY: Consolas; mso-bidi-font-family: Consolas"><SPAN
style="mso-spacerun: yes"> </SPAN>}<o:p></o:p></SPAN></P></SPAN></DIV>
<DIV><SPAN class=763415815-03062011><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=763415815-03062011><FONT face=Arial size=2>So after the tags
have tried to be read, if no tags could be read, check the MPEG header. This
seems ok to me providing the first 4 bytes of the file would ALWAYS be the start
of an MPEG header for valid MP3 file.</FONT></SPAN></DIV>
<DIV><SPAN class=763415815-03062011><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=763415815-03062011><FONT face=Arial size=2>Is this approach any
good?</FONT></SPAN></DIV>
<DIV><SPAN class=763415815-03062011><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=763415815-03062011><FONT face=Arial
size=2>Thanks,</FONT></SPAN></DIV>
<DIV><SPAN class=763415815-03062011><FONT face=Arial
size=2>David</FONT></SPAN></DIV>
<DIV><SPAN class=763415815-03062011><FONT face=Arial
size=2></FONT></SPAN> </DIV></BODY></HTML>