Audio file in jar made by Eclipse IDE

落爺英雄遲暮 提交于 2019-12-14 04:08:56

问题


I have an swing app. Where I use wav file to make alarm. I put Alarm.wav in folder where I have *.class is bin folder. And it works. I use this code to get wav file and play it.

    InputStream in;
    try {

        InputStream is = getClass().getResourceAsStream("Alarm.wav");
        AudioInputStream audioInputStream = AudioSystem
                .getAudioInputStream(is);       
        AudioPlayer.player.start(audioInputStream);
    } catch (FileNotFoundException e) {

        e.printStackTrace();
    }

But when I made in Eclipse runnable jar there is no sound in my app.


回答1:


I have similiar problem. Try use this code:

InputStream in;
    try {

        AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(getClass().getResource("Alarm.wav"));       
        AudioPlayer.player.start(audioInputStream);
    } catch (FileNotFoundException e) {

        e.printStackTrace();
    }


来源:https://stackoverflow.com/questions/17436808/audio-file-in-jar-made-by-eclipse-ide

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!