开发者

Playing module music in Java [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 7 years ago.

Improve this question

How can I play module music (.it, .mod, .xm or .s3m files) in a Java application? (Standar开发者_开发百科d Java for desktop machines)

I tried looking at the open source JavaMod, but it had too many files so I didn't know where to start, and the pre-built .jar file wouldn't even run on my machine.


Add javamod.jar to the application class path and try with this code:

public static void main(String[] args) {

    try {
        Helpers.registerAllClasses();
        File music = new File("c:\\test3.XM");
        Properties props = new Properties();
        props.setProperty(ModContainer.PROPERTY_PLAYER_ISP, "3");
        props.setProperty(ModContainer.PROPERTY_PLAYER_STEREO, "2");
        props.setProperty(ModContainer.PROPERTY_PLAYER_WIDESTEREOMIX, "FALSE");
        props.setProperty(ModContainer.PROPERTY_PLAYER_NOISEREDUCTION, "FALSE");
        props.setProperty(ModContainer.PROPERTY_PLAYER_NOLOOPS, "FALSE");
        props.setProperty(ModContainer.PROPERTY_PLAYER_MEGABASS, "TRUE");
        props.setProperty(ModContainer.PROPERTY_PLAYER_BITSPERSAMPLE, "16");
        props.setProperty(ModContainer.PROPERTY_PLAYER_FREQUENCY, "48000");
        MultimediaContainerManager.configureContainer(props);
        URL modUrl = music.toURI().toURL();
        MultimediaContainer multimediaContainer = MultimediaContainerManager.getMultimediaContainer(modUrl);
        Mixer mixer = multimediaContainer.createNewMixer();
        mixer.startPlayback();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        System.exit(3);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

Works fine for me. But I would also suggest to try running javamod stand-alone in order to make sure it works on your system.


To get JavaMod to run on your machine, you have to run it with the java -jar command.

This screenshot illustrates how to do this:

Playing module music in Java [closed]


Whoa, cool that JavaMod even exists to play old school modules in Java. I doubt you're going to find much better support these days. Honestly you're best bet is probably going to be to figure out how to call into that library, or just use the source code directly. You'll likely have to look through the code to determine how to integrate with it. By the way, I'm able to run it fine by just double clicking on the .jar file (I'm using Java 6 Update 24 on Windows 7).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜