How to control mp3 audio volume using JMF in JAVA

306 Views Asked by At

I am using JMF for playing mp3 Audio file.It is playing but I have no idea how to control its volume? I am using

Player audioPlayer = Manager.createRealizedPlayer(url);
audioPlayer.start();
2

There are 2 best solutions below

2
AudioBubble On

I did it on Android in this fashion.

audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
        final int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
        int curVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);



        SeekBar volumecontrol = (SeekBar) findViewById(R.id.seekBar);

        volumecontrol.setMax(maxVolume);
        volumecontrol.setProgress(curVolume);
        volumecontrol.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromuser) {

                audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,progress, 0);

            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });
0
Andrew Thompson On

See Player.getGainControl() which:

Gets the object for controlling this Player's audio gain. If this player does not have a GainControl, getGainControl returns null. For example, getGainControl might return null if the Player does not play audio data.

On GainControl:

GainControl is an interface for manipulating audio signal gain.

Gain and Gain Measures

Gain is a multiplicative value applied to an audio signal that modifies the amplitude of the signal. This interface allows the gain to be specified in either decibels or using a floating point value that varies between 0.0 and 1.0.