Java检测音频文件(mp3) [英] Java detecting an audio file (mp3)

查看:787
本文介绍了Java检测音频文件(mp3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码读取mp3文件

I have this code that reads an mp3 file

import java.io.File;
import java.io.IOException;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.UnsupportedAudioFileException;

    public class Sound {
        public static void main(String[] args) {
            File sampleFile = new File("test.mp3");
            try {
                AudioSystem.getAudioFileFormat(sampleFile);
            } catch (UnsupportedAudioFileException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }

这里的问题是它返回文件不支持异常,这里的文件是一个mp3文件。 Java不支持mp3文件?如果有的话,其他什么来验证音频文件?(比如ogg,wav)

The problem here is that it is returning file not supported exception, the file here is an mp3 file. Java doesn't support mp3 files? if so what are others to validate an audio file?(like ogg, wav)

推荐答案

你可以看看 Apache Tika 库。它可以通过其内容检测文件的类型并提取文件元数据。它支持 mp3格式。

You may take a look at Apache Tika library. It can detect type of a file by its content and extract file metadata. It supports mp3 format.

这是示例。

Here is an example of file type detection with Apache Tika.

这篇关于Java检测音频文件(mp3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆