【问题标题】:JMF + mp3plugin.jar mp3 files is not playingJMF + mp3plugin.jar mp3 文件无法播放
【发布时间】:2013-02-18 15:28:21
【问题描述】:

我有这个代码:

    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 文件可以正常播放。

有什么想法吗?

【问题讨论】:

  • 从 1.3 开始,J2SE 就有了 Java Sound。播放(短)MP3 所需的只是javasound 信息中的代码。页面,以及运行时类路径上的 mp3plugin.jar

标签: java mp3 javasound jmf


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

    以下是我播放音乐所需的全部内容。

    public static void main(String args[]) throws NoPlayerException, CannotRealizeException, IOException {
        MediaLocator ml = new MediaLocator((new File("roar_of_future.mp3").toURL()));
        Player player = Manager.createRealizedPlayer(ml);
        player.start();
    }
    

    所以请确保mp3plugin.jar 在类路径中,并且您的 javasdk 是 Java 8(32 位)或 7(32 位),因为 JMF 不适用于 Java 9 及更高版本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-27
      相关资源
      最近更新 更多