android-visualizer icon indicating copy to clipboard operation
android-visualizer copied to clipboard

Making visualization independent of the volume

Open mobilevisuals opened this issue 9 years ago • 5 comments

If the volume is high, the FFT values are also higher. This will make the music visualization dependent on the volume, which is not a good thing. It should be the same visualization for low and high volumes. I found an interesting and easy solution to that problem:

http://stackoverflow.com/questions/8048692/android-visualizer-fft-waveform-affected-by-device-volume

It works for apps, which have their own music player, because they then have a MediaPlayer object. The Equalizer and the Visualizer must have the same audio session id for this to work. That session id belongs to the MediaPlayer object.

The problem is that it does not work for external media players, like Spotify. The visualization becomes dependent on the volyme there. There is no option get a handle to a mediaplayer object for Spotfify, so I have to set the audioSessionID to 0. This means any player currently used. This will however make the volume code not work.

Has someone a good suggestion to make this work on external players too? It would help me a lot to keep improving my apps. The following are the code i added to the apps. The first code works and is for apps with their own player . The second code is for external players like Spotify and it does not work.

  1. Internal players:

// Create the Visualizer object and attach it to our media player. mVisualizer = null; int sessionId = player.getAudioSessionId(); mEqualizer = new Equalizer(0, sessionId); mEqualizer.setEnabled(true); mVisualizer = new Visualizer(sessionId);

  1. External players:

    mVisualizer = null; int sessionId = 0; mEqualizer = new Equalizer(0, sessionId); mEqualizer.setEnabled(true); mVisualizer = new Visualizer(sessionId);

mobilevisuals avatar Apr 23 '15 12:04 mobilevisuals

Has anyone found a solution to this? It is very annoying that this works on iOS, but not on Android.

mobilevisuals avatar Feb 14 '16 13:02 mobilevisuals

I can't find a solution either, did someone found a fix already?

NFSS10 avatar Jan 26 '17 00:01 NFSS10

I tried the second code and it seems worked! I was use the Locamedia App(A mediaplayer running backgroung in service), then the visualizer is in another App. oh,sorry, It`s on Android.

BTW,I test mEqualizer.setEnabled(true) ,mVisualizer.setEnabled(true) .but the visualization still depends on volume

tracyliu1 avatar Dec 28 '17 10:12 tracyliu1

There is a method on the Visualizer class called SetScalingMode - have you tried that?

hallidev avatar Mar 08 '18 00:03 hallidev

I'm encountering the same problem. I'm enabling the equalizer, setting the scaling mode to normalized, and still getting audio-dependent FFT data for a Visualizer with an audioSession of 0

timendez avatar Apr 11 '19 23:04 timendez