Adjusting Volume using JLayer

前端 未结 2 732
刺人心
刺人心 2021-01-17 05:06

me and a friend are programming a MP3 Player as a schoolproject. We are nearly finished and now stuck at the point where we try to programm a function to change the volume o

2条回答
  •  春和景丽
    2021-01-17 05:30

    JLGUI is a good example of a UI-based JLayer app adjusting volume. You can get the source code in the tar.gz file. http://www.javazoom.net/jlgui/sources.html

        if (src == ui.getAcVolume())
        {
            Object[] args = { String.valueOf(ui.getAcVolume().getValue()) };
            String volumeText = MessageFormat.format(ui.getResource("slider.volume.text"), args);
            ui.getAcTitleLabel().setAcText(volumeText);
            try
            {
                int gainValue = ui.getAcVolume().getValue();
                int maxGain = ui.getAcVolume().getMaximum();
                if (gainValue == 0) theSoundPlayer.setGain(0);
                else theSoundPlayer.setGain(((double) gainValue / (double) maxGain));
                config.setVolume(gainValue);
            }
            catch (BasicPlayerException ex)
            {
                log.debug("Cannot set gain", ex);
            }
        }
    

提交回复
热议问题