我想我已经阅读了关于这个问题的所有内容,但还没有找到有效的答案。有人能帮我在mediaplayer上添加混响吗?这是我添加PresetReverb 的代码
mediaPlayer = MediaPlayer.create(this, R.raw.song)
val presetReverb = PresetReverb(1, 0)
presetReverb.preset = PresetReverb.PRESET_LARGEHALL
presetReverb.enabled = true
mediaPlayer.attachAuxEffect(presetReverb.id)
mediaPlayer.setAuxEffectSendLevel(1.0f)
mediaPlayer.start()
以及添加EnvironmentalReverb
mediaPlayer = MediaPlayer.create(this, R.raw.song)
environmentalReverb = EnvironmentalReverb(0, 0)
environmentalReverb.decayTime = 2000
environmentalReverb.reflectionsDelay = 250
environmentalReverb.reflectionsLevel = -8500
environmentalReverb.roomLevel = -8500
mediaPlayer.attachAuxEffect(environmentalReverb.id)
environmentalReverb.enabled = true
mediaPlayer.setAuxEffectSendLevel(1.0f)
mediaPlayer.start()
还添加了权限
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
所以我尝试了使用getAudioSessionId((,尝试了audioSession0和1,它们都没有创建混响。当我编写mediaPlayer.prepare()
时,应用程序崩溃了。Logcat中没有错误。也许还有另一种方法可以创造混响?
我发现问题出在播放器的音量上,它掩盖了混响效果。解决方案是将播放器的音量降低到0.5甚至0.0,然后增加全局设备音量。
mediaPlayer = MediaPlayer.create(this, R.raw.song)
val presetReverb = PresetReverb(1, 0)
presetReverb.preset = PresetReverb.PRESET_LARGEHALL
presetReverb.enabled = true
mediaPlayer.attachAuxEffect(presetReverb.id)
mediaPlayer.setAuxEffectSendLevel(1.0f)
mediaPlayer.setVolume(0.0f,0.0f);
mediaPlayer.prepare();
mediaPlayer.start()