Skip to content Skip to sidebar Skip to footer

Adjust Dash Stream Volume With Android Exoplayer

I'm trying to set up a seekbar to control the level of an instance of exoplayer streaming dash. The setup I am using is a modified version of the demo project and am having trouble

Solution 1:

If I read the ExoPlayer source code correctly you have to keep references to the audioRenderers you use when preparing the ExoPlayer instance.

exoPlayer.prepare(audioRenderer);

To change volume you have to send the following message:

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

First you pass the audioRenderer for which you want to change the volume. Secondly you define the message which you want to send to the renderer which is MSG_SET_VOLUME, since you want to affect audio. Finally you pass the value you want to set the volume to. In this example I chose 0.1f but of course you can use any value which fits your needs.

You can effect two different playback volumes if you send messages to both MediaCodecAudioTrackRenderers which you used to prepare playback. So you could send two messages with for example value 0.4f for audioRenderer1 and 0.6f for audioRenderer2 to blend the playbacks into one another.

I did not try this myself, but I think it should work.

This is the snippet of the original ExoPlayer code which is responsible for handling the MSG_SET_VOLUME message:

publicvoidhandleMessage(int messageType, Object message)throws ExoPlaybackException {
    if (messageType == MSG_SET_VOLUME) {
        audioTrack.setVolume((Float) message);
    } else {
        super.handleMessage(messageType, message);
    }
}

Post a Comment for "Adjust Dash Stream Volume With Android Exoplayer"