将均衡器附加到Android全局音频输出 [英] Attaching Equalizer to Android global audio output
问题描述
我正计划为Android开发一个均衡器应用.我在Equalizer类文档此处中注意到了,它说:
I am planning to make an equalizer app for Android. I noticed in the Equalizer class documentation here, it says:
注意:不赞成使用会话0将均衡器附加到全局音频输出混合.
NOTE: attaching an Equalizer to the global audio output mix by use of session 0 is deprecated.
我从其他问题中看到,尽管不建议使用此功能,但在某些Android版本中仍然可行;但是,最新答案是2013年的答案.
I see from other questions that although this is deprecated, it was still possible in certain Android versions; however the most recent answer is from 2013.
在最新的Android版本(5.1棒棒糖)中,仍然可以通过会话0将均衡器附加到全局音频吗?如果没有,建议将均衡器应用于全局音频的推荐方法是什么?
Is it still possible to attach an Equalizer to global audio via session 0 in the latest Android version (5.1 Lollipop)? If not, what is the recommended way to apply an equalizer to global audio going forward?
推荐答案
According to Android, you can use ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION to receive the id of a playing audio session:
旨在向效果控制应用程序或服务发出信号,通知它打开了新的音频会话,并要求应用音频效果.
Intent to signal to the effect control application or service that a new audio session is opened and requires audio effects to be applied.
我尝试在清单中添加常数,但它仅适用于Spotify和Youtube Music等音乐应用程序:
I tried adding the constant in the manifest, but it only worked for music apps such as Spotify and Youtube Music:
<receiver android:name=".receivers.AudioSessionReceiver">
<intent-filter>
<action android:name="android.media.action.OPEN_AUDIO_EFFECT_CONTROL_SESSION"/>
</intent-filter>
</receiver>
然后,您可以使用ID创建一个附加到会话ID的均衡器.
Then, you can use the id to create an equalizer attached to the session id.
public class AudioSessionReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
int id = intent.getIntExtra(Equalizer.EXTRA_AUDIO_SESSION, -1);
String packageName = intent.getStringExtra(Equalizer.EXTRA_PACKAGE_NAME);
}
}
这篇关于将均衡器附加到Android全局音频输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!