问题
I am planning to make an equalizer app for Android. I noticed in the Equalizer class documentation here, it says:
NOTE: attaching an Equalizer to the global audio output mix by use of session 0 is deprecated.
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.
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?
回答1:
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.
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>
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);
}
}
来源:https://stackoverflow.com/questions/29531184/attaching-equalizer-to-android-global-audio-output