2017-09-15 227 views
0

我试图导出我的游戏与音乐束。当我用音乐导出游戏(文件大小为300mb(资源文件夹大小约为300 mb))Java Eclipse与源文件夹导出游戏

当我运行该jar然后我听不到声音。我试着用CMD它显示了以下错误:

enter image description here

任何帮助吗?

编辑

SoundManager类类:

package com.memequickie.sound; 

import java.io.File; 
import javax.sound.sampled.AudioSystem; 
import javax.sound.sampled.Clip; 

public class SoundManager { 
    Clip clip; 
    public boolean playSound(File sound) { 
     boolean ended = false; 
     try { 
      clip = AudioSystem.getClip(); 
      clip.open(AudioSystem.getAudioInputStream(sound)); 
      clip.start(); 
      if(clip.getMicrosecondLength() == clip.getMicrosecondPosition()) 
      { 
       ended = true; 
      } 
     } catch(Exception e) { 
      System.out.println("Error with playing sound."); 
      e.printStackTrace(); 
     } 
     return ended; 
    } 

    public void stopSound() { 
     clip.stop(); 
    } 
} 

编辑 我试图InputStream和它仍然不能得到工作。 enter image description here

+1

您无法将jar条目作为文件访问。 –

+0

你的'SoundManager'类是什么样的? –

+0

为'SoundManager'类添加的代码 – MemesTV

回答

1

AudioSystem.getAudioInputStream(File)预计Music6.wav作为一个真正的文件,为JAR内部的压缩文件

如果要将音频文件发送到JAR内部,则必须使用AudioSystem.getAudioInputStream(InputStream)而不是audio file as InputStream包裹在BufferedInputStream中。

+0

请参阅我的文章中的编辑部分。 – MemesTV

+0

如果你需要一个文件(因为你想标记和重置音频,这似乎不被'InputStream's支持),你只有两个选择不将音频文件打包到JAR文件中或者解压音频文件暂时在使用之前。 – howlger

+0

我只想播放音乐文件。没有花哨的东西。 – MemesTV