音频不会在罐发挥,但不会在日食 [英] Audio does not play in Jar but does in eclipse

查看:226
本文介绍了音频不会在罐发挥,但不会在日食的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行JAR声音不玩了,但是当我在Eclipse中运行它。

Sound does not play when I run the JAR, but it does when I run it in eclipse.

下面是我加载剪辑:

public void init(){
    System.out.println("grabbing Music");
    String currentDir = new File("").getAbsolutePath();
    name=new File(currentDir+"\\music\\").list();
    clip=new Clip[name.length];
    soundFile=new File[name.length];
    for(int x=0;x<name.length;x++){
        System.out.println(currentDir+"\\music\\"+name[x]);
        try {
            soundFile[x]= new File(currentDir+"\\music\\"+name[x]);
            AudioInputStream sound = AudioSystem.getAudioInputStream(soundFile[x]);
            DataLine.Info info= new DataLine.Info(Clip.class, sound.getFormat());
            clip[x] = (Clip) AudioSystem.getLine(info);
            clip[x].open(sound);
            clip[x].addLineListener(new LineListener(){
                public void update(LineEvent event) {
                    if (event.getType() == LineEvent.Type.STOP) {
                        event.getLine().close();
                    }
                }
            });
        } catch (LineUnavailableException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (UnsupportedAudioFileException e) {
            e.printStackTrace();
        }
    }

}

在Eclipse中运行时,我没有得到任何错误。不应该有一个无效目录错误的可能性,所以有什么不好?

I do not get any errors when running it in Eclipse. There should be no possibility of an invalid directory error, so what is wrong?

- 当瓶子在CMD运行我没有得到任何错误。

-When the jar is run in CMD i get no errors.

编辑:我觉得我加载音频错的,因此为什么我粘贴了code我用来加载中的文件在我的搜索我还没有看到任何人使用文件中的声音文件加载。不知道这是什么问题?

edit: I feel like I am loading the audio wrong, hence why I pasted the code I used to load the files in. In my searches I haven't seen anyone use File to load in a sound file. Wonder if that is the problem?

推荐答案

怎么样 -


  1. 右键点击在Eclipse项目。然后新建 - >源文件夹

  2. 命名源文件夹任何东西。例如music_src。

  3. 复制或在music_src拖累整个音乐目录。然后,让罐子。

这篇关于音频不会在罐发挥,但不会在日食的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆