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
0
Question by chrisjjones · Aug 03, 2012 at 07:33 PM · iosaudioiphonexcodevolume

Getting iOS device volume

Hi,

I am trying to figure out a way to retrieve the current volume from an iOS device. I don't need to change it...just retrieve it. I thought about using a plugin for this, but I don't really want to poll the device, but rather have the device fire an event that talks back to Unity via the UnitySendMessage callback.

I found the following code bits while researching the issue, but I can't seem to get them to work properly as I really have no idea where they are supposed to go.

 // Volume control notification
     
     [[NSNotificationCenter defaultCenter]
      addObserver:self
      selector:@selector(volumeChanged:)
      name:@"AVSystemController_SystemVolumeDidChangeNotification"
      object:nil];


 - (void) volumeChanged:(NSNotification *) notification
 {
     float volume = [[[notification userInfo]
                     objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"]
                     floatValue];
     
     NSString *volString = [NSString stringWithFormat: @"%f",volume];
     const char* volChar = [volString UTF8String];
     UnitySendMessage("AudioManager","OnVolumeChanged",volChar);
 }

I have tried putting the event registration in various places around the AppController.mm, but it never seems to fire the actual event. My Obj-C is very weak, so I'm sure I'm doing something blatantly wrong. Anybody have any suggestions?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by agamedesigner · Aug 03, 2012 at 08:13 PM

I think this might help: http://stackoverflow.com/questions/7207417/how-to-detect-an-iphone-ipod-volume-level

Comment
Add comment · Show 3 · 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 chrisjjones · Aug 03, 2012 at 08:22 PM 0
Share

I did run across this in my search and this would be an alternate way of getting the device volume (there were several I found), but how do I tie that into an event that is fired when someone actively changes the volume on the device?

avatar image agamedesigner · Aug 03, 2012 at 08:37 PM 0
Share

how about this: http://stackoverflow.com/questions/6164471/listen-to-a-value-change-of-my-text-field

avatar image chrisjjones · Aug 03, 2012 at 09:57 PM 0
Share

I think I already have that part of it down. I did add the following right above my notification registration code, but it didn't seem to make a difference, which I put in the startUnity function.

AudioSessionInitialize(NULL, NULL, NULL, NULL); AudioSessionSetActive(true);

http://stackoverflow.com/questions/7749030/objective-c-volumechanged-wasnt-called-even-add-a-observer-for-avsystemcontrol

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

8 People are following this question.

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

Related Questions

IPhone 4 and IPad 2 lost audio on resume 0 Answers

iphone sound disappearance - ios build or hardware issue? 2 Answers

The presence of 3rd party libraries in our Unity XCode project causes mono-land exceptions leading to a crash immediately after startup. 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