在Java中播放.mp3 [英] Play .mp3 in Java

查看:105
本文介绍了在Java中播放.mp3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题之前已经在此站点上已经问过,但是我的问题有点偏离了.

I know this question has already been asked on this site before, but my question deviates from it a little.

我想在不使用外部Java库(例如javafx)的情况下播放.mp3文件.这有可能吗?如果可以,您该怎么做?我对图书馆javafx没有什么反对,我只是想知道这是出于教育目的.

I want to play a .mp3 file without using external Java libraries such as javafx. Is this possible, and if so, how do you do it? I have nothing against the library javafx, I just want to know for educational purposes.

我知道,有了javax库,您可以轻松播放.wav文件.

I know that with the javax libraries you can play .wav files quite easily.

public void playSound() {
try {
    AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File("D:/Music/test.wav").getAbsoluteFile());
    Clip clip = AudioSystem.getClip();
    clip.open(audioInputStream);
    clip.start();
    } catch(Exception e) {
    e.printStackTrace();
    }
}

如果使用此库只能播放.wav个文件,为什么只选择一种文件类型?仅仅是开发人员的选择,还是选择某种文件类型的策略?与其他文件类型相比,访问.wav文件有速度上的好处吗?

If you can only play .wav files with this library, why only that one file type? Was it just the developers choice, or was there some sort of strategy in choosing this one file type? Is there some speed benefit from accessing .wav files over some other file type?

推荐答案

据我所知,MP3已受专利保护,不能包含在标准编解码器中.

MP3 is patent encumbered and cannot be included in the standard set of codecs, as far as I know.

这篇关于在Java中播放.mp3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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