• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by joonturbo · Jun 11, 2015 at 04:28 PM · androidandroidplugin

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();
 }
 
 }



Comment
Talenos

People who like this

1 Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image aadithyabk · Jun 22, 2015 at 11:49 PM 0
Share

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

avatar image Talenos · Dec 01, 2015 at 11:31 PM 0
Share

I am also seeing this behavior. I eagerly anticipate a solution :)

I'm seeing this on version 5.2

avatar image joonturbo Talenos · Dec 02, 2015 at 12:42 AM 0
Share

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.

avatar image Talenos joonturbo · Dec 02, 2015 at 12:46 AM 0
Share

We've submitted it as a bug to Unity. I'll report back what I hear.

avatar image BenoitFreslon · Feb 15, 2017 at 04:27 PM 0
Share

Did you found a workaround? It always returns True on Unity 5.5.1p3

1 Reply

  • Sort: 
avatar image
Best Answer

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.

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Update about the future of Unity Answers

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta later in June. Please note, we are aiming to set Unity Answers to read-only mode on the 31st of May in order to prepare for the final data migration.

For more information, please read our full announcement.

Follow this Question

Answers Answers and Comments

24 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I add a custom icon to an android game? 0 Answers

How do I make an Android plugin for unity? 0 Answers

How to alter the Android Manifest to use my ad-displaying activity in Unity? 0 Answers

[Android] Call .jar function on render thread using JNI 0 Answers

CommandInvokationFailure: Failed to re-package resources. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges