views:

58

answers:

1

Hey there,

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 of the player. We are using:

  • AudioDevice
  • AdvancedPlayer

I know someone else asked the same question allready but I did not quite get the solution and I didn't want to respond to such an old question so I thought I'm just gonna ask again.

Cheers Timothy

A: 

Hi, 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);
        }
    }
Chris Dennett
that if/else formatting makes my head hurt.
akf
Hey thanks for the quick answer ! I'll check it out and ask again if I don't get it :-)
Timothy
Ohh emm could you just quickly tell me in which file the code you posted is found ? Cheers
Timothy
PlayerUI.java :) In \src\javazoom\jlgui\player\amp
Chris Dennett
Okay I found it but I don't get it :-/ . theSoundPlayer is a BasicController but I can't find that Class anywhere ...
Timothy
The volume adjsutment code is apparently in javazoom.jlgui.basicplayer.BasicPlayer but I can't find the file! There's only the player package. Annoying :)
Chris Dennett
http://www.koders.com/java/fid518DAD29BA2B356FB9FB827BB313929A8CBA2865.aspx?s=BasicPlayer.java
Chris Dennett
Cheers for the link ! And the search goes on hehe. Can't imgagine why the Jlayer devolepers didn't include the function directly into the jlayer libary
Timothy
It looks like you have to adjust the volume on the implementation level (where it uses the javax.sound classes) -- the abstraction literally doesn't have the adjustment in it :)
Chris Dennett
please check my answer , it doesn't work right now but I don't know why yet. I think I kind of have to like it with my AudioDevice but I've got no idea how ...
Timothy