Android – 均衡器usePreset不工作(声音效果无变化)

我正在研究流式广播应用.除了改变均衡器效果不影响声音之外,一切正常.

通过调用usePreset(预设)更改均衡器效果不会对声音效果进行任何更改.

即使没有错误,为什么usePreset不会改变声音效果.

我已经用4.0.3测试了三星galaxy sII.

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());
        }
    }

感谢您的帮助以确定问题.

编辑
此问题尚未解决.我没有找到任何解释Equalizer Preset使用的示例代码.

对使用Preset welcome的代码示例的任何引用.

最佳答案
this is a fully source code for equalizer,希望这会对你有所帮助

点赞