Here you can find the source of isMP3(File file)
Parameter | Description |
---|---|
file | the file to be checked |
public static boolean isMP3(File file)
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class Main { /** The Constant MP3_MEDIA_TYPE. */ private static final String MP3_MEDIA_TYPE = "audio/mpeg"; /**/*ww w.j a v a 2 s .c o m*/ * Checks if is mp3. * * @param file the file to be checked * @return true, if the file is a valid mp3 */ public static boolean isMP3(File file) { try { Path filepath = Paths.get(file.getAbsolutePath()); String contentType = Files.probeContentType(filepath); if (contentType.equals(MP3_MEDIA_TYPE)) return true; } catch (IOException e) { System.err.println("Error while detecting media type"); } return false; } }