0

Actually I'm working on Video player then i have one requirement i.e., How to Add the Volume Increase and Decrease options using seekbar on Swipeup(); and swipe down on onToucheventListener. I have no idea to add the above functionality if possible please tell me the process or please provide the sample code. please help me.

Bertram Gilfoyle
  • 9,899
  • 6
  • 42
  • 67
Ashok
  • 11
  • 2
  • 1
    Possible duplicate of [Using SeekBar to Control Volume in android?](https://stackoverflow.com/questions/10134338/using-seekbar-to-control-volume-in-android) – InsaneCat May 03 '18 at 05:16
  • First learn about touchlisteners and calculate amount of `x` swiped and get it into min-max value and set it to volume – karanatwal.github.io May 03 '18 at 05:24

2 Answers2

1

I've implemented volume control in one of my online radio stream project like this, and it worked fine for me

        private SeekBar volumeSeekbar;

        volumeSeekbar = (SeekBar) findViewById(R.id.seekBarVolume);
        volumeSeekbar.setThumbOffset(5);
        volumeSeekbar.setMax(audioManager
                .getStreamMaxVolume(AudioManager.STREAM_MUSIC));
        volumeSeekbar.setProgress(audioManager
                .getStreamVolume(AudioManager.STREAM_MUSIC));


    volumeSeekbar.setOnSeekBarChangeListener(this);

    private void volume(String volume) {
    if (volume.equals("up")) {
        audioManager.adjustVolume(AudioManager.ADJUST_RAISE,
                AudioManager.FLAG_SHOW_UI);

        volumeSeekbar.setProgress(audioManager
                .getStreamVolume(AudioManager.STREAM_MUSIC));

    } else if (volume.equals("down")) {
        audioManager.adjustVolume(AudioManager.ADJUST_LOWER,
                AudioManager.FLAG_SHOW_UI);

        volumeSeekbar.setProgress(audioManager
                .getStreamVolume(AudioManager.STREAM_MUSIC));

    } else if (volume.equals("max")) {

        if (isMute)
            unmute();
        audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,
                audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC),
                0);
        volumeSeekbar.setProgress(audioManager
                .getStreamVolume(AudioManager.STREAM_MUSIC));
    }
}

public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
        volume("down");
    }

    if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)) {
        volume("up");
    }

    if ((keyCode == KeyEvent.KEYCODE_BACK)) {
        moveTaskToBack(true);

    }
    return true;
}

 @Override
public void onProgressChanged(SeekBar seekBar, int progress,
                              boolean fromUser) {
    audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, progress, 0);
    if (AudioManager.STREAM_MUSIC > 0) {
        buttonMinMute.setBackgroundResource(R.drawable.speaker_low_range);
        audioManager.setStreamMute(AudioManager.STREAM_MUSIC, false);
    }

}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {

}
Zobair Alam
  • 527
  • 1
  • 5
  • 24
0

I need an ontouchevent listener please see the below mentioned image.

When I swipeup on linearRight, how do I increase the volume and at the same time increase the seekbar indicator?

code Displayed on image

erikrunia
  • 2,371
  • 1
  • 15
  • 22
Ashok
  • 11
  • 2