Вопрос

I am working on streaming radio application. everything is working fine except the changing the equalizer effect does not affect sound.

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

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

I have tested in 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 issue.

EDIT This issue is not resolved yet. i did not find any sample code which explain Equalizer Preset usage.

Any reference to code sample which uses Preset welcome.

Это было полезно?

Решение

Другие советы

I have the same problem. When I load it on emulator it produce an error that I don't really know why, it always says ...audiofx.Equalizer. and audiofx.AudioEffect. or something similar. But I have discovered that if you have other media player like n7player in my case, try to close it and try again your media player. In my case it works, but I think that it has to be one method to get some equalizer that is active.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top