简体   繁体   English

JMF + mp3plugin.jar mp3 文件不播放

[英]JMF + mp3plugin.jar mp3 files is not playing

I have this code :我有这个代码:

    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();
        }
    }
}

i'm trying to play an mp3 file, mp3plugin is added to the project lib as well as the jmf jar.我正在尝试播放 mp3 文件,mp3plugin 已添加到项目库以及 jmf jar 中。 there's no error on the console but cant hear a sound.控制台上没有错误,但听不到声音。

the file is not playing.该文件没有播放。 .wav files are playing fine. .wav 文件播放正常。

any idea ?任何的想法 ?

JMF is a bad option. JMF 是一个糟糕的选择。 The project was abandoned long time ago.该项目很久以前就被放弃了。 I have answered a similar question here:我在这里回答了一个类似的问题:

Java - Error when trying to use mp3plugin for playing an mp3 file Java - 尝试使用 mp3plugin 播放 mp3 文件时出错

it might be usefull for you - Im using Java Sound它可能对你有用 - 我正在使用 Java Sound

The following is all I need to play music.以下是我播放音乐所需的全部内容。

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();
}

So please make sure mp3plugin.jar is in the classpath and your javasdk is Java 8 (32bit) or 7 (32bit) because JMF is not working on Java 9 and above.因此,请确保mp3plugin.jar在类路径中,并且您的 javasdk 是 Java 8(32 位)或 7(32 位),因为 JMF 不适用于 Java 9 及更高版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM