JavaDefaultSoundManager.java 文件源码

java
阅读 19 收藏 0 点赞 0 评论 0

项目:monkey-shines-java-port 作者:
/**
 * Automatically called on construction and game setting change to match clip volume to
 * user defined levels. Does nothing if there is no background music
 * 
 * @param value
 *      percentage to set music volume to
 */
private void setMusicVolume(int value) {
    if (bgm.isPresent() ) {
        Clip mus = bgm.get();
        if (value == 0) {
            musicOff = true;
            // unlike sounds, music must manually be shut off, and then back on again if required.
            if (mus.isRunning() ) {
                musicCut = true;
                mus.stop();
            }
            return;
        } else {
            // if the music was previously cut because it was already running, then and only then do
            // we resume it.
            if (musicCut) {
                musicCut = false;
                mus.start();
            }
        }

        if (bgm.isPresent() ) {
            musicOff = false;
            FloatControl gainControl = (FloatControl) bgm.get().getControl(FloatControl.Type.MASTER_GAIN);
            float decibelLevelOffset = SoundUtils.resolveDecibelOffsetFromPercentage(value);
            // Music seems to be naturally louder than sound effects, so give it a negative nudge.
            decibelLevelOffset -= 10;
            System.out.println("Decibel offset for music: " + decibelLevelOffset);
            gainControl.setValue(decibelLevelOffset);
        } else {
            musicOff = true;
        }
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号