- Home /
Detect if music is playing in other apps on Android
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();
}
}
Did you find a solution ? It returns true because Unity acquires the speakers. If you just a build a native android application, it works fine. I want to achieve something similar
I am also seeing this behavior. I eagerly anticipate a solution :)
I'm seeing this on version 5.2
please consider upvoting this question if you're seeing the same behavior. I posted a bug about it which you can track here: http://fogbugz.unity3d.com/default.asp?705207_8pp7q015bil7mqnm though it would be nice if someone would post it on the public bug tracker too.
We've submitted it as a bug to Unity. I'll report back what I hear.
Did you found a workaround? It always returns True on Unity 5.5.1p3
Answer by Talenos · Dec 04, 2015 at 04:01 PM
We heard back from Unity today, it sounds like when they revamped the audio for 5.0 they completely rewrote the Android player and introduced this issue. They should be working on a fix for a future 5.x release.
Your answer
Follow this Question
Related Questions
Error converting bytecode to dex: Cause: com.android.dex.DexException: Multiple dex files define 0 Answers
Calculating linear acceleration of a phone on Android 1 Answer
how I send a mail using android in unity 5, when I compile it in the cell not it sends the message 0 Answers
Error while importing confluent packages and bundling it into an APK 0 Answers
Android Multi-Plugins 0 Answers