如何将所有系统范围(本机)音频效果继承到媒体播放器应用程序中?
How to inherit all systemwide (native) audio effects into a mediaplayer app?
如何从播放音频流的应用程序继承和启用(使之生效)当前音频效果(低音增强、均衡器等),假设设备上有其他一些应用程序可用于处理本机语调算法。
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 设置进行定期更改,还需要通过 OnParameterChangeListener 进行检测。
如何从播放音频流的应用程序继承和启用(使之生效)当前音频效果(低音增强、均衡器等),假设设备上有其他一些应用程序可用于处理本机语调算法。
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 设置进行定期更改,还需要通过 OnParameterChangeListener 进行检测。