Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controlling the volume of Exoplayer with a seekbar

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!

like image 888
Max Marshall Avatar asked Jul 27 '15 09:07

Max Marshall


People also ask

How do I hide SeekBar in ExoPlayer?

You can do it simply by creating a layout named: exo_playback_control_view. xml and override the regular XML. On this one below is the standard XML, You can add android:visiblite="invisible" for DefaultTimeBar which is what I think you're trying to hide, if not feel free change it as you want.

How do you add a listener to ExoPlayer?

Registering a listener to receive such events is easy: // Add a listener to receive events from the player. player. addListener(listener);


1 Answers

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.

like image 82
SANAT Avatar answered Sep 18 '22 13:09

SANAT