Attaching Equalizer to Android global audio output

旧城冷巷雨未停 提交于 2020-01-02 05:47:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!