【问题标题】:AndEngine : Music volume won't adjust correctlyAndEngine : 音乐音量无法正确调整
【发布时间】:2015-05-12 09:24:44
【问题描述】:

我在onSceneTouchEvent 中使用以下代码:

if(audioControlButton.contains(pSceneTouchEvent.getX(), pSceneTouchEvent.getY())
         && pSceneTouchEvent.getAction() == TouchEvent.ACTION_DOWN) {
    toggleVolume();
}

一切正常,方法在必要时调用。 toggleVolume() 有这个实现:

if(levelMusic.getVolume() != 0f) {
    levelMusic.setVolume(0f);
} else { 
    levelMusic.setVolume(100f);
}

所有条件似乎都有效,但问题就在这里: 如果 levelMusic.setVolume(0f) 被调用,音乐音量应该被禁用,但如果 levelMusic.setVolume(100f) 调用我仍然听不到音乐

注意:我也尝试过pause()resume(),但效果不佳

我的 levelMusic 变量:

Music levelMusic; //field in scene class
levelMusic = data.getLevelMusic();
levelMusic.play();

在 onResourcesLoadingFinished

编辑:我也尝试将值设置为 60 而不是 100 和 0,9f(如果 max malue 为 1f),但它也不起作用

【问题讨论】:

  • 您是否尝试为您的选项屏幕实现静音/取消静音音乐?

标签: android andengine


【解决方案1】:

如果有人会遇到这个问题:

使用 levelMusic.setVolume(0.0f, 0.0f); // 0f wont work

所以,整个方法应该是这样的:

if(levelMusic.getVolume() != 0.0f) {
    levelMusic.setVolume(0.0f, 0.0f);
} else { 
    levelMusic.setVolume(1f);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-15
    相关资源
    最近更新 更多