public static long getID3v2Length ( File file ) throws IOException { BufferedInputStream in = new BufferedInputStream ( new FileInputStream ( file ) ) ; try { byte buffer [ ] = new byte [ 10 ] ; if ( in . read ( buffer ) != 10 ) return 0 ; if ( buffer [ 0 ] != ' ' || buffer [ 1 ] != ' ' || buffer [ 2 ] != ' ' ) return 0 ; return 10 + bytesToLength ( new byte [ ] { buffer [ 6 ] , buffer [ 7 ] , buffer [ 8 ] , buffer [ 9 ] } ) ; } finally { in . close ( ) ; } }
Takes the given file opens the header and reads the ID3v2 header size . The returned value is inclusive of the header preamble so taking the returned value and skipping exactly that number of bytes will place the read cursor at the correct beginning of the actual MP3 data . If the ID3v2 header is missing or the file is shorter than 10 bytes returns 0 .