andEngine中的声音问题

时间:2012-09-05 05:14:57

标签: android andengine

我正在使用andEngine开发游戏。我想为这个游戏添加背景音。我尝试实现声音,但声音没有播放。请帮助我。这是我的代码:

onLoadEngine()

return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE,
                new FillResolutionPolicy(), this.mCamera).setNeedsSound(true))

onLoadResources()

 Sound bgSound;
 SoundFactory.setAssetBasePath("gfx/");
 this.bgSound = SoundFactory.createSoundFromAsset(this.mEngine.getSoundManager(), this,              "bg.mid");
 bgSound.setLoopCount(-1);
 bgSound.play();

1 个答案:

答案 0 :(得分:1)

将这两行移至onCreateScene()方法:

 bgSound.setLoopCount(-1);
 bgSound.play();

另外,请致电SoundFactory.createMusicFromAsset而不是SoundFactory.createSoundFromAsset