java - JMF + mp3plugin.jar mp3 文件无法播放

标签 java mp3 javasound jmf

我有这段代码:

    package test;

import java.io.File;

import javax.media.Format;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.Player;
import javax.media.PlugInManager;
import javax.media.format.AudioFormat;

public class AudioTest {
    public static void main(String[] args) {
        Format input1 = new AudioFormat(AudioFormat.MPEGLAYER3);
        Format input2 = new AudioFormat(AudioFormat.MPEG);
        Format output = new AudioFormat(AudioFormat.LINEAR);
        PlugInManager.addPlugIn(
            "com.sun.media.codec.audio.mp3.JavaDecoder",
            new Format[]{input1, input2},
            new Format[]{output},
            PlugInManager.CODEC
        );
        try{
            Player player = Manager.createPlayer(new MediaLocator(new File("1.mp3").toURI().toURL()));
            player.realize();
                        player.start();
        }
        catch(Exception ex){
            ex.printStackTrace();
        }
    }
}

我正在尝试播放 mp3 文件,mp3plugin 已添加到项目库以及 jmf jar。 控制台没有错误,但听不到声音。

文件没有播放。 .wav 文件播放正常。

有什么想法吗?

最佳答案

JMF 是一个糟糕的选择。该项目很久以前就被放弃了。 我在这里回答过类似的问题:

Java - Error when trying to use mp3plugin for playing an mp3 file

它可能对你有用 - 我正在使用 Java Sound

关于java - JMF + mp3plugin.jar mp3 文件无法播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14939709/

相关文章:

java - 配置 Jackson 以反序列化单引号(无效)JSON

java - 如何画出尽可能准确的蝴蝶曲线?

javax.sound.sampled.UnsupportedAudioFileException : could not get audio input stream from input file when loading wav file

java - Web 服务 - 实现端的超时

java - 如何在java中将URL存储在字符串中

html - 在mp3旁使用firefox时,请使用其他音效来源

python - 需要什么样的对象作为 mutagen.mp4.MP4Cover 中的第一个参数?

bash - 在启动时保持 bash 脚本在后台循环的最佳方法是什么 - Linux?

java - 定序器接收器时间戳始终输出-1

java - 使用java将音频文件与文本匹配