Android - Equalizer usePreset does not work (without changing the sound effect)

I am working on a streaming radio application. everything works fine, except that changing the equalizer effect does not affect the sound.

Changing the equalizer effect when calling usePreset (preset) does not make any changes to the sound effects.

Even if there is no error, why usePreset does not change the sound effects.

I tested on samsung galaxy sII with 4.0.3.

public void startPlayer() { // // Check whether we can acquire the audio focus // to start the player // if (!requestAudioFocus()) { return; } if (null != mAudioPlayer) { if (mAudioPlayer.isPlaying()) { mAudioPlayer.stop(); } mAudioPlayer.reset(); } else { mAudioPlayer = new MediaPlayer(); mAudioPlayer.reset(); } try { notifyProgressUpdate(PLAYER_INITIALIZING); try { mEqualizer = new Equalizer(0, mAudioPlayer.getAudioSessionId()); mEqualizer.setEnabled(true); Log.d(TAG, "Audio Session ID " + mAudioPlayer.getAudioSessionId() + "Equalizer " + mEqualizer + " Preset " + mEqualizer.getCurrentPreset()); } catch (Exception ex) { mEqualizer = null; } mAudioPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mAudioPlayer.setDataSource(mCurrentTrack.getStreamURL()); // // Add the Listener to track the player status // mAudioPlayer.setOnCompletionListener(this); mAudioPlayer.setOnBufferingUpdateListener(this); mAudioPlayer.setOnPreparedListener(this); mAudioPlayer.setOnInfoListener(this); mAudioPlayer.setOnErrorListener(this); notifyProgressUpdate(PLAYER_BUFFERING); mAudioPlayer.prepareAsync(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } //Get the available presets from the equalizer public String[] getEqualizerPresets() { String[] presets = null; short noOfPresets = -1; if (null != mEqualizer) { noOfPresets = mEqualizer.getNumberOfPresets(); presets = new String[noOfPresets]; for (short index = 0; index < noOfPresets; index++) { presets[index] = mEqualizer.getPresetName(index); } } return presets; } //Set the user preferred presets public void setEqualizerPreset(int position) { if (null != mEqualizer) { Log.d(TAG, "setting equlizer effects " + position); Log.d(TAG, "Equalizer " + mEqualizer + " set Preset " + position); mEqualizer.usePreset((short)position); Log.d(TAG, "Equalizer " + mEqualizer + " current Preset " + mEqualizer.getCurrentPreset()); } } 

Appreciate your help to identify the problem.

EDIT This problem has not yet been resolved. I did not find an example code that explains the use of a predefined equalizer.

Any reference to a sample code that uses a preset.

+4
source share
2 answers
+1
source

I have the same problem. When I load it into the emulator, it causes an error, which I really don’t know why it always talks about ... audiofx.Equalizer. and audiofx.AudioEffect. or something similar. But I found that if in my case you have another media player, for example n7player, try closing it and try your media player again. In my case, this works, but I think this should be one way to get an active equalizer.

+1
source

Source: https://habr.com/ru/post/1480049/


All Articles