Search code examples
javamp3javasoundjmf

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. there's no error on the console but cant hear a sound.

the file is not playing. .wav files are playing fine.

any idea ?


Solution

  • JMF is a bad option. 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

    it might be usefull for you - Im using Java Sound