Saturday 26 February 2022

ExoPlayer with Equalizer - sound too loud at start

I have an Android app, where music is being played using the ExoPlayer. I've added Equalizer functionality, but it seems that on some devices (Pixel 6, Huawei P40) there is an issue, when Equalizer is being enabled. When ExoPlayer is initialized and equalizer.setEnabled(true) is called, there is a very loud sound for a few miliseconds. Although it is very short, it seems that it is caused by increasing the volume of the particular stream significantly, until it's back to normal. When I tried to delay setEnabled(true) call for a few seconds, the issue was resolved, but this doesn't feel like correct approach.

Has anybody of you encountered this issue and solved it? I tried to enable the equalizer in different places (when instantiating the ExoPlayer instance, in onPlaybackStateChanged method, etc.), but the issue was always there.

Code:

exoPlayer = new ExoPlayer.Builder(context).build();
equalizer = new Equalizer(0, exoPlayer.getAudioSessionId());
equalizer.setEnabled(true);
// Bands and presets are set here
// ...
// exoplayer is prepared, listeners are added, etc.

I'm sure the issue is caused by Equalizer, because if the equalizer-related code is not called, or if equalizer.setEnabled() is called with false, everything is OK.



from ExoPlayer with Equalizer - sound too loud at start

No comments:

Post a Comment