You need, intent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, mp.getAudioSessionId();)
then you need, but you need a MediaPlayer, variable, you need the display equalizer intent together with the audioSession and getPackageName in the same intent effects.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, this.getPackageName());
also, Intent intent = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL);
with the audiosession and package name. display intent first, then the audiosession and getpackagename,
Then in the service you need. Only if more than one song is playing. You need the following code in the service, otherwise the eqaulizer won't always work.
public void openAudioFx() {
Intent i = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION);
i.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName);
i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, audioSession);
this.sendBroadcast(i);
}
public void closeAudioFx() {
Intent k = new Intent(AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION);
k.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName);
k.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, audioSession);
this.sendBroadcast(k);
}
then you have to receive the broadcast, to make it work all the time you need to make a an int audioSession = 0;
and String getPackageName = getPackageName();
Then you need, to broadcast package name maybe and audiosession, then use the variables, instead of code. The eqaulizer display intent, and package name and audioeffect, are necessary for the intent display equalizer to work, only works in an Activity.
The broadcast receiver I think try to use. the class,
public final BroadcastReceiver hello;
{
hello = new BroadcastReceiver() {
private static final String TAG = "mMessageReceiver";
@Override
public void onReceive(Context context, Intent intent) {
if (intent != null) {
String action = intent.getAction();
switch (action) {
case AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION:
// Log.d(TAG_MAIN_ACTIVITY, action);
break;
case AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION:
break;
case AudioEffect.EXTRA_AUDIO_SESSION:
audioSession = intent.getIntExtra(AudioEffect.EXTRA_AUDIO_SESSION, 0);
break;
case AudioEffect.EXTRA_PACKAGE_NAME:
// Log.d(TAG_MAIN_ACTIVITY, action);
break;
then you need to broadcast the packagename from the service, to activity figure it out. with a variable required higher then somehow use string, to the pacakename broadcast, then use the variable higher and in the broadcast. Then put this in, onCreate public final BroadcastReceiver hello;
{
hello = new BroadcastReceiver() {
private static final String TAG = "mMessageReceiver";
@Override
public void onReceive(Context context, Intent intent) {
if (intent != null) {
String action = intent.getAction();
switch (action) {
case AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION:
// Log.d(TAG_MAIN_ACTIVITY, action);
break;
case AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION:
break;
case AudioEffect.EXTRA_AUDIO_SESSION:
audioSession = intent.getIntExtra(AudioEffect.EXTRA_AUDIO_SESSION, 0);
break;
case AudioEffect.EXTRA_PACKAGE_NAME:
// Log.d(TAG_MAIN_ACTIVITY, action);
break;
}
LocalBroadcastManager.getInstance(this).registerReceiver(hello, new IntentFilter("ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION"));
LocalBroadcastManager.getInstance(this).registerReceiver(hello, new IntentFilter("ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION"));
LocalBroadcastManager.getInstance(this).registerReceiver(hello, new IntentFilter("EXTRA_PACKAGE_NAME"));
LocalBroadcastManager.getInstance(this).registerReceiver(hello, new IntentFilter("EXTRA_AUDIO_SESSION"));
done. Hopefully it works, let me know I may respond if anything is missing. Sorry some of the code is not formatted properly, please read and put all the code together, then if you can see writing, after code, then please separate.