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
5
Question by Jaap Kreijkamp · Mar 09, 2010 at 03:20 AM · audioiphone

Detecting ipod music playback

It seems that in the current version (1.6.0f1) of Unity iPhone it's possible to play a compressed audio stream whilst ipod is playing music. Although I haven't really analysed it, it looks like the Unity music stream is decoded in software when the ipod background music is playing (sounds logical as there's supposedly only one hardware decode path).

As I actually like to give the player the option to have his ipod music playing, is there a way from within Unity to detect if music is already playing or not, or must I write a plugin for that?

(Browsing through the script reference it seems there isn't a way to do this from within Unity, but maybe I'm missing something or maybe there's an undocumented feature :-))

Comment
Add comment
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

5 Replies

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

Answer by Dimitris 1 · Jul 22, 2010 at 02:50 PM

For this purpose I wrote this plugin and added it to my appDelegate.m (renamed to .mm and compiled as a C++ file):

extern "C" {

 bool _IsMusicPlaying () {
     BOOL isPlaying = NO;
     MPMusicPlayerController* iPodMusicPlayer = [MPMusicPlayerController iPodMusicPlayer];
     if (iPodMusicPlayer.playbackState == MPMusicPlaybackStatePlaying) {
         isPlaying = YES;
     }
     NSLog(@"Music is %@.", isPlaying ? @"on" : @"off");
     return isPlaying;
 }   

}

Unity can then call this method through a plugin class and get the state of the iPod music. I hope that's useful.

EDIT (added unity code too): In the Assets/Plugin folder of your unity project, create a OBJCPlugin.cs file and add:

using UnityEngine; using System.Runtime.InteropServices;

public class OBJCPlugin {

 [DllImport ("__Internal")]
 private static extern bool _IsMusicPlaying ();

 public static bool IsMusicPlaying ()
 {
     if ( Application.platform == RuntimePlatform.IPhonePlayer )
     {
         return _IsMusicPlaying();
     }
     else {
         return false;
     }
 }

}

Then you can call that static method of that class from any other class.

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 lathomas64 · Jul 07, 2010 at 06:31 PM

I think a much simpler solution would be to provide the player with an option to mute your game.

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
0

Answer by andeeee · Mar 24, 2010 at 07:09 PM

There isn't anything like this in the Unity API, but you can probably get what you need with a plugin.

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
0

Answer by JDonavan 1 · Apr 07, 2010 at 01:05 AM

One solution might be to modify the Objective C shell that Unity creates and have it do the check for the iPod audio playback and write something to the player prefs.

Comment
Add comment · Show 1 · 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 Dreamora · Jun 13, 2010 at 01:02 AM 0
Share

To add to that: Should also be pretty much straight forward if you download Apples Add$$anonymous$$usic example project + readup on NSUserDefaults (-> PlayerPrefs in unity)

avatar image
0

Answer by fireDude67 · Jul 14, 2010 at 05:04 PM

Another way is that you could post an idea on feedback.unity3d.com and maybe it will get released in unity 3.1 or something

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

No one has followed this question yet.

Related Questions

IPhone 4 and IPad 2 lost audio on resume 0 Answers

iPhone pitch not working? 1 Answer

Sound on collision with rigidbody and rigidbody 2 Answers

How to NOT play audio in silent mode with iOS? 1 Answer

How to avoid 'auto audio volume decrease' on iphone? 3 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