6

I'm trying to control the volume of an Exoplayer isntance that is streaming DASH in my project using a seekbar. The issue I am coming up against is that my renderers and player are split up between classes a la the demo project. Currently my three main classes are my DashRendererBuilder and Player and Player activity. I have my seekbar in my Player activity and I'm wondering how I can reference the necessary player and renderer within my PlayerActivity in order to control the volume of my Exoplayer.

From past questions I have been informed that

exoPlayer.sendMessage(audioRenderer, MediaCodecAudioTrackRenderer.MSG_SET_VOLUME, 0.1f);

is the end message I am looking to send however as I have said due to everything being split between classes I am having trouble with the referencing of individual components.

Ideally I would like to be able to have two exoplayer instances with a seekbar controlling the mix of the two so that is my end goal.

It would be great to get some feedback or get pointed in the right direction for this problem so any and all help is much appreciated. Thanks very much guys!

Max Marshall
  • 257
  • 2
  • 3
  • 13
  • 1
    You can use my answer here http://stackoverflow.com/questions/27404446/mute-audio-on-exoplayer/27404447#27404447 – Hugo Gresse Jul 30 '15 at 12:48

1 Answers1

6

AudioManager is helpful for handling the system volume. To control the volume with ExoPlayer, just use this :

Create AudioManager object :

AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

Handle volume using Seekbar :

volumeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                audioManager.setStreamVolume(exoPlayer.getAudioStreamType(), i, 0);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });

If you want to handle hardware volume up/down key + Seekbar then just check my answer.

Community
  • 1
  • 1
SANAT
  • 8,489
  • 55
  • 66
  • 3
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/16072536) – Gustavo Morales May 09 '17 at 11:37
  • @MoralesBatovski sure :) – SANAT May 09 '17 at 12:47