felixpalmer / android-visualizer

Takes the input from the Android MediaPlayer and displays visualizations, like in iTunes or WinAmp
811 stars 278 forks source link

Making visualization independent of the volume #19

Open mobilevisuals opened 9 years ago

mobilevisuals commented 9 years ago

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 commented 8 years ago

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

NFSS10 commented 7 years ago

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

tracyliu1 commented 6 years ago

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

hallidev commented 6 years ago

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

timendez commented 5 years ago

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