I’m trying to detect whether music is playing in any other apps (Which should mute my game’s music).
(AudioManager)UnityPlayer.currentActivity.getSystemService(Context.AUDIO_SERVICE).isMusicActive
seems to always return true.
I made a native plugin which works, in so far that it returns a value, but it’s always true. Am I missing something?
package com.glitchnap.glitchandroid;
import android.os.Bundle;
import android.util.Log;
import android.content.Context;
import android.media.AudioManager;
import com.unity3d.player.UnityPlayer;
public class GlitchAndroid {
public boolean isMusicPlaying() {
Log.i("GLITCHANDROID", "isMusicPlaying?");
AudioManager aMan = (AudioManager)UnityPlayer.currentActivity.getSystemService(Context.AUDIO_SERVICE);
return aMan.isMusicActive();
}
}