You can check if music is playing as described from this post.
AudioManager manager = (AudioManager)this.getSystemService(Context.AUDIO_SERVICE);
if(manager.isMusicActive())
{
// do something - or do it not
}
Wrap it around a class in Java then call it from C# with the help of the AndroidJavaClass
API.
But that requires Java. You can take that code and convert it to C# without Java at-all. Get UnityPlayerPlayer, Activity then the Context. The rest can be handled by AndroidJavaClass
.
Here is the ported C# version that does not require Java plugin.
bool isMusicPlaying()
{
const string AUDIO_SERVICE = "audio";
AndroidJavaClass unityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject unityActivity = unityClass.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject unityContext = unityActivity.Call<AndroidJavaObject>("getApplicationContext");
bool mIsPlaying;
using (AndroidJavaObject audioManager = unityContext.Call<AndroidJavaObject>("getSystemService", AUDIO_SERVICE))
{
mIsPlaying = audioManager.Call<bool>("isMusicActive");
}
return mIsPlaying;
}