I am new to this and I don't know what to do? I want to compare two MP3 files and check whether they are same or different. I want to check it by its content. please help me. I searched everywhere but not getting anything.
            Asked
            
        
        
            Active
            
        
            Viewed 1,329 times
        
    2
            
            
        - 
                    Why does it necessarily need to be an mp3 API, couldn't you just compare the file sizes or would files be different sizes but contain the same song? – David Mar 06 '13 at 10:08
- 
                    what means `MP3 contents`? ID3? bytecode? – oliholz Mar 06 '13 at 10:08
- 
                    i want to check whether they contain same song or not – Vinay Mar 06 '13 at 10:12
- 
                    1Comparing audio files is like comparing images, hard. If a single thing changes, like if it is compressed with other setting, re-compressed, byte comparison will will fail. So the best way to do such a thing is to look for something that can do that, and look how you could integrate that into Java. See [wikipedia](http://en.wikipedia.org/wiki/Acoustic_fingerprint) for some introduction. – Johannes Kuhn Mar 06 '13 at 10:12
2 Answers
1
            
            
        You can use Guava Libraries
Perform a crc32 checksum calculation
File myfile1 = new File("file1.mp3");
long checksum1 = Files.getChecksum(myfile1 , new java.util.zip.CRC32());
File myfile2 = new File("file2.mp3");
long checksum2 = Files.getChecksum(myfile2 , new java.util.zip.CRC32());
if (checksum1 == checksum2)    {
    System.out.println(" Both are same ");
    // your business logic
}
In case you are not satisfied with checksum and want to do  a sha-256 digest calculation 
byte[] digest = Files.getDigest(myfile1 , MessageDigest.getInstance("SHA-256"));
 
    
    
        AurA
        
- 12,135
- 7
- 46
- 63
- 
                    Or calculate the checksum without an additional lib: http://stackoverflow.com/a/304350/1165132 – Adrian Mar 06 '13 at 10:13
- 
                    Original poster clarifies that "i want to check whether they contain same song or not" not if the files are identical, which is what this will do. – Bjorn Roche Mar 06 '13 at 15:17
- 
                    Why not simply compare the files byte-by-byte? They have to be read from disk anyway, so why do all the extra math? – Bjorn Roche Mar 06 '13 at 15:18
0
            
            
        You say "I searched everywhere but not getting anything." If this is true, then you searched for the wrong thing. I just went to google and typed "stack overflow check if two songs are the same" and got these two answers to your question:
Is it possible to see if two MP3 files are the same song by analyzing the files' bytes?
Java: Comparing two audio files to see if they are the same "music"
You might also look into the echonest API and echoprint.
 
    
    
        Community
        
- 1
- 1
 
    
    
        Bjorn Roche
        
- 11,279
- 6
- 36
- 58
 
    