Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by NateJC · May 16, 2016 at 04:14 AM · c#iosmusicitunesradio

iOS Requirement (A10.16) Ensure that when iTunes Radio is playing, Game Music must be set to “Off” automatically

I'm getting this bug report back on my game and I have no idea how to solve it. Does anyone know how to detect when iTunes Radio starts or stops using c# or how to go about solving this issue? (To clarify, I'm not asking how to start/stop my music, but rather how do I knew when to start/stop my music).

Comment
Add comment · Show 1
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 ChimeraSW · Jun 04, 2016 at 12:47 AM 0
Share

Did you solve for this? We are hitting the same issue, any guidance you're willing to share?

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by JDAUL · Jun 16, 2016 at 05:38 AM

Hey there @ChimeraSW, here is a simple plugin we used to accomplish what you want:

Save it as DetectMusicPlayer.mm or something similar, and place it in your Plugins/iOS folder.

 #import <MediaPlayer/MediaPlayer.h>
 
 extern "C" {
 
     bool _DetectMusicPlayer() {
         
         bool playerDetectedAndPlaying = false;
         NSString *reqSysVer = @"3.0";
         NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
         if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending){
             Class MusicPlayerController = NSClassFromString(@"MPMusicPlayerController");
             if (MusicPlayerController){         
                 id myMusicPlayerController = [[MusicPlayerController alloc]init];
                 id MusicPlayer = [[myMusicPlayerController class] iPodMusicPlayer ];
                 if ( [ MusicPlayer playbackState ] == MPMusicPlaybackStatePlaying ) {
                     playerDetectedAndPlaying = true;
                 }
             }
         }
 
         return playerDetectedAndPlaying;
     }
     
     void _ResumeMusicPlayer()
     {
         
         NSString *reqSysVer = @"3.0";
         NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
         if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending){
             Class MusicPlayerController = NSClassFromString(@"MPMusicPlayerController");
             if (MusicPlayerController){
                 id myMusicPlayerController = [[MusicPlayerController alloc]init];
                 id MusicPlayer = [[myMusicPlayerController class] iPodMusicPlayer ];
                 if ( [ MusicPlayer playbackState ] != MPMusicPlaybackStatePlaying ) {
                     [myMusicPlayerController play];
                 }
             }
         }
     }
     
 }
 

Then, in another script, say DetectMusicPlayer.cs, give a callback to the native plugin like so:

 using UnityEngine;
 using System.Collections;
 using System.Runtime.InteropServices;
 
 public class DetectMusicPlayer
 {
     #if UNITY_IOS
     [DllImport("__Internal")]
     static private extern bool _DetectMusicPlayer();
     [DllImport("__Internal")]
     static private extern void _ResumeMusicPlayer();
     #endif
 
     static public bool Detect()
     {
         #if UNITY_IOS
         return _DetectMusicPlayer();
         #else
             return false;
         #endif
     }
 
     static public void ResumePlayer()
     {
         #if UNITY_IOS
         Debug.Log("Resuming music player");
         _ResumeMusicPlayer();
         #endif
     }
 }
 
 //Usage example
 /*
 //Some global Listener class...
 
 void OnApplicationFocus(bool isFocused)
 {
     bool musicPlaying = DetectMusicPlayer.Detect();
 
     if (musicPlaying)
     {
         // Mute game music here...
     }
     else
     {
         //Unmute game music here...
     }
 }
 
 */
 

Hope this helps!

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
avatar image
1

Answer by samonte.rey · May 16, 2016 at 05:16 PM

I personally did not solve it but a member in our team did. The solution was to write a native plugin that detects when iTunes radio was playing.

Comment
Add comment · Show 2 · 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
avatar image NateJC · May 16, 2016 at 05:26 PM 0
Share

I don't suppose this is a plugin you guys would be willing to share? :)

avatar image samonte.rey NateJC · May 16, 2016 at 06:00 PM 0
Share

Hey Nate. Unfortunately I cannot share it. :(

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

150 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to know if my speakers are mute? c# android/ios 0 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Unity IAP Services not Working on iOS. Purchase Dialogue does not Show at All 6 Answers

iOS music player & youtube mutes sound in app 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