Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
1
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
Add comment · 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

· Add your reply
  • Sort: 
avatar image
0
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
Add comment · 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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

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

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


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