如何从应用程序播放AudioStreams的应用程序中继承和启用(制作有效的)当前音频效应(Bassboost,均衡器等),假设设备上可以使用其他应用程序来操纵该设备天然语调算法。
API文档在如何实现这一方面并不明显。
以下内容不起作用,或者不足:
Equalizer equalizer = new Equalizer(0, mediaPlayer.getAudioSessionId());
equalizer.setEnabled(true);
mediaPlayer.prepare();
mediaPlayer.start();
我可以回答自己。明显的解决方案应该是:
Equalizer.inheritSystemEq()
我只以以下繁琐的方式工作。请注意,该解决方案已弃用,但未弃用的解决方案尚未被替代API替换。
Equalizer equalizerSystem = new Equalizer(0, 0) //0 as second parameter is deprecated.
//get current eq settings for global mix out
short band0 = equalizerSystem.getBandLevel((short) 0);
short band1 = equalizerSystem.getBandLevel((short) 1);
short band2 = equalizerSystem.getBandLevel((short) 2);
short band3 = equalizerSystem.getBandLevel((short) 3);
short band4 = equalizerSystem.getBandLevel((short) 4);
equalizerSystem.release();
//copy these "system" values (Set by another equalizer app) into
//another equalizer instance particular for this audio session.
Equalizer equalizer = new Equalizer(0, mediaPlayer.getAudioSessionId());
equalizer.setEnabled(true);
equalizer.setBandLevel((short) 0, band0);
equalizer.setBandLevel((short) 1, band1);
equalizer.setBandLevel((short) 2, band2);
equalizer.setBandLevel((short) 3, band3);
equalizer.setBandLevel((short) 4, band4);
最后,即随后,请致电MediaPlayer.prepare()或MediaPlayer.prepareasync,否则equalizerSystem = new Equalizer(0,0)
将不起作用。
也设置在AndroidManifest中:
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
要采用对EQ设置的重复更改,还需要通过onGarameterChangelistener检测到这一点。