开发者

Android class MediaPlayer's attachAuxEffect does not work

开发者 https://www.devze.com 2023-03-20 17:01 出处:网络
I write the following code and apply them after the playback starts(mp.start()). PresetReverb pr = new PresetReverb(100, 0);

I write the following code and apply them after the playback starts(mp.start()).

  PresetReverb pr = new PresetReverb(100, 0);
  mp.attachAuxEffect(pr.getId());
  mp.setAux开发者_如何学PythonEffectSendLevel((float)0.7);

And i could not hear any difference from when I don't apply the above code. Why? How to use this method? I already add the permission MODIFY_AUDIO_SETTINGS by the way.


You can try with following code:

PresetReverb pr = new PresetReverb(0, 0);
pr.setPreset(PRESET_LARGEHALL);
pr.setEnabled(true);
mp.attachAuxEffect(pr.getId());
mp.setAuxEffectSendLevel((float)0.7); 


Use it like

PresetReverb mReverb = new PresetReverb(0,mMediaPlayer.getAudioSessionId());//<<<<<<<<<<<<<
mReverb.setPreset(PresetReverb.PRESET_SMALLROOM);
mReverb.setEnabled(true);
mMediaPlayer.setAuxEffectSendLevel(1.0f);

And no need to call mMediaPlayer.attachAuxEffect(mReverb.getId()) . It is already set. And global audio Session id 0 is deprecated..

0

精彩评论

暂无评论...
验证码 换一张
取 消