【在Java中播放声音效果】教程文章相关的互联网学习教程文章

Java-Android Soundpool无法播放声音【代码】

我在使用SoundPool类播放多个声音效果时遇到麻烦.基本上,我正在制作一个实时游戏,其中涉及用户点击屏幕上的一堆对象.每当玩家触摸物体时,我都需要播放声音.因此,我转向了SoundPool类.下面是我的代码:private SoundPool mSoundPool; private int mSoundId;protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);PreferencesManager.getInstance(this);setContentView(R.layout.arcademode);ini...

java-如何使按钮在Libgdx中播放声音?【代码】

当鼠标悬停在TextButton上时,如何使它播放声音?就像是:TextButton play = new TextButton("Play", textButtonStyle); play.addListener(new ButtonHoverListener() {@Overridepublic void doSomething() {...} });解决方法: play.addListener(new InputListener(){boolean playing = false;@Overridepublic void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {super.enter(event, x, y, pointer, f...

在Java中播放声音效果【代码】

我正在尝试执行此代码行的等效操作,只是用一个小的mp3文件代替系统提示音:Toolkit.getDefaultToolkit().beep();我有一个mp3文件,但要播放一点声音效果.这是一个相对容易的事情吗?有人可以告诉我执行此操作的代码吗?解决方法:您可以使用MediaPlayer播放声音.这是我通常用于所有音频的内容.public class APP extends Activity {//ADD THIS LINE AND IMPORT MediaPlayer MediaPlayer btnClick;@Override public void onCreate(Bund...

如何在Java中以给定的采样率播放声音?【代码】

我想知道是否有一个库或某些东西在给定的采样率(20-20,000 Hz)下播放声音.实际上,我找到了something,但我不明白我是如何让它工作的!解决方法:这是完整的示例,不需要任何外部库:import javax.sound.sampled.*;public class SoundUtils {public static float SAMPLE_RATE = 8000f;public static void tone(int hz, int msecs) throws LineUnavailableException {tone(hz, msecs, 1.0);}public static void tone(int hz, int msecs,...

java – Eclipse的JAR文件不播放声音【代码】

我有一个项目,我想导出为jar文件.该软件应该在某个时间点播放声音.但是,问题是当达到该时间点时,JAR文件不播放声音文件.当我从Eclipse IDE运行相同的项目时,它确实如此. 以下代码显示了我如何设置声音播放功能:public void setupSoundPlayback(){try{buzzer = AudioSystem.getClip();in = AudioSystem.getAudioInputStream(BatteryBeeper.class.getResourceAsStream("/sound/boing_x.wav"));buzzer.open(in);}catch(Exception e){...

错误播放声音java(无行匹配接口剪辑支持格式)【代码】

我们正试图在我们的一个项目中集成声音,我的团队成员没有得到这个错误,我在两台不同的机器上得到它. 堆栈跟踪:Exception in thread "SoundPlayer" java.lang.IllegalArgumentException: No line matching interface Clip supporting format PCM_SIGNED 16000.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian, and buffers of 11129272 to 11129272 bytes is supported. at javax.sound.sampled.AudioSystem.getLine(Unknown ...

播放 - 相关标签