我似乎无法找到如何将 SoundPool 添加到我的特定游戏
I cannot seem to find how to add SoundPool to my specific game
所以我是 java 的新手,并且有一款游戏主要 activity 一个名为 "Game" 的 class 扩展了 Activity, "MainThread" 和扩展 SurfaceView 的 GamePanel class
http://blog.ashwanik.in/2014/12/play-sounds-in-android-application.html
SoundPoolManager.CreateInstance();
List<integer> sounds = new ArrayList<integer>();
sounds.add(R.raw.first);
sounds.add(R.raw.second);
sounds.add(R.raw.third);
SoundPoolManager.getInstance().setSounds(sounds);
try {
SoundPoolManager.getInstance().InitializeSoundPool(this, new ISoundPoolLoaded() {
@Override
public void onSuccess() {
}
});
} catch (Exception e) {
e.printStackTrace();
}
问题是,当我将上面的代码添加到游戏 class(主)或游戏面板(其中包含游戏中的大部分代码)时,它不会给我一个错误或任何它根本不播放声音的东西,大部分教程都有关于如何使用按钮进行播放的解释,但我似乎找不到如何让它在实际游戏中播放的内容
SoundPool
class可以帮助我们管理一次渲染的音频流的数量。 SoundPool 异步加载声音,但是直到 Android API 级别 8,我们无法确定声音是否已正确加载。这就是为什么我们应该检查示例是否加载在 OnLoadCompleteListener
中。
因此,在本示例中,我们将创建一个应用程序,它使用 Android SoundPool.class.
播放、循环播放、停止和暂停蜂鸣声
请检查此 tutorial。
所以我是 java 的新手,并且有一款游戏主要 activity 一个名为 "Game" 的 class 扩展了 Activity, "MainThread" 和扩展 SurfaceView 的 GamePanel class http://blog.ashwanik.in/2014/12/play-sounds-in-android-application.html
SoundPoolManager.CreateInstance();
List<integer> sounds = new ArrayList<integer>();
sounds.add(R.raw.first);
sounds.add(R.raw.second);
sounds.add(R.raw.third);
SoundPoolManager.getInstance().setSounds(sounds);
try {
SoundPoolManager.getInstance().InitializeSoundPool(this, new ISoundPoolLoaded() {
@Override
public void onSuccess() {
}
});
} catch (Exception e) {
e.printStackTrace();
}
问题是,当我将上面的代码添加到游戏 class(主)或游戏面板(其中包含游戏中的大部分代码)时,它不会给我一个错误或任何它根本不播放声音的东西,大部分教程都有关于如何使用按钮进行播放的解释,但我似乎找不到如何让它在实际游戏中播放的内容
SoundPool
class可以帮助我们管理一次渲染的音频流的数量。 SoundPool 异步加载声音,但是直到 Android API 级别 8,我们无法确定声音是否已正确加载。这就是为什么我们应该检查示例是否加载在 OnLoadCompleteListener
中。
因此,在本示例中,我们将创建一个应用程序,它使用 Android SoundPool.class.
请检查此 tutorial。