【发布时间】:2014-08-06 09:23:24
【问题描述】:
我正在制作游戏并想为我的角色选择页面添加声音。所以我创建了一个可以播放歌曲的 Java 文件,但是如何让歌曲文件在我的角色选择屏幕启动时播放?
注意: 两个文件在同一个包中。
package comp_sci;
import java.io.*;
import sun.audio.*;
public class PlaySound
{
public static void main(String[] args)
throws Exception
{
// open the sound file as a Java input stream
String gongFile = "music.wav";
InputStream in = new FileInputStream(gongFile);
// create an audiostream from the inputstream
AudioStream audioStream = new AudioStream(in);
// play the audio clip with the audioplayer class
AudioPlayer.player.start(audioStream);
}
}
这是我的声音文件。为了让它在我的其他程序中播放,我尝试了下面的代码,但没有成功。
PlaySound winn2 = new PlaySound();
【问题讨论】:
标签: java audio startup joptionpane