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
1
Question by tinklife · Aug 25, 2016 at 01:07 PM · audioiphonebug-perhapsvolume

How to avoid 'auto audio volume decrease' on iphone?

As gamer, I usually listen to podcast with bluetooth while playing games on my iPhone.

I prefer to set audio volume settings to 20% BGM, 50% SFX volume and device master volumes to best-fit for podcast.

So, I can clearly listen to what podcast saying, but not killing all the moods of game by mute.
I'm disturbed when I found my game(in-dev) automatically cut my podcast volume about half when it launches on my iPhone.
I googled and found someone saying iOS automatically adjust audio to app's audio data to protect ear and to avoid hearing problem for being exposed to loud sound.

So, I tried change all volumes of sound clips, but it doesn't help. And I played some recent games that might be unity-powered, also show same situation, which I didn't see this before. ( Tinker Island, Dungeon Warfare, Build Away! and such.. )

I've been awful experiences with them because I need to change device master volume every time when I turn on and off games, with sudden loud surprises.

As developer, what I want to do is prevent this from my game.
Is there any particular settings to avoid this?
Is this something new bug of latest Unity?

I noticed this 'reduced volume' during 5.4 beta-period(with my in-dev game),
and currently using release version of 5.4.0.3 (no patch applied.) and iPhone 6+ with iOS 9.3.4.

Did someone notice this? Does it bother or not?

Comment
Add comment · Show 2
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 thorn-erikson · Sep 01, 2016 at 07:44 AM 0
Share

I noticed the problem aswell. Very annoying. I'm pretty sure it is a Unity bug. Haven't yet found a way to prevent this, sadly.

avatar image tinklife · Sep 02, 2016 at 03:44 PM 0
Share

At first, I thought It might be UnityAds's movie volume was the main cause of this problem, but my new project (for next prototype idea) without UnityAds also has this problem.

3 Replies

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

Answer by lanestp · Sep 30, 2016 at 05:03 PM

I had this problem, VERY irritating. I fixed it by adding a plugin that swizzles AVAudioSession. Here's my code, I hope it helps.

 #import <UIKit/UIKit.h> 
 #import <AVFoundation/AVFoundation.h> 
 #import <objc/runtime.h>
 
 @interface AudioFix : NSObject 
 @end
 
 __strong AudioFix *sharedInstance;
 
 @implementation AVAudioSession(AudioFix)
 
 + (void)load { 
 sharedInstance = [[self alloc] init]; 
 } 
 - (BOOL)newsetCategory:(NSString *)category 
 withOptions:(AVAudioSessionCategoryOptions)options 
 error:(NSError * _Nullable *)outError { 
 options = AVAudioSessionCategoryOptionMixWithOthers; 
 return [self newsetCategory:category withOptions:options error:outError]; 
 }
 
 - (id)init { 
 if (!(self = [super init])) return nil; 
 
 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; 
 [nc addObserverForName:UIApplicationDidFinishLaunchingNotification 
 object:nil 
 queue:[NSOperationQueue mainQueue] 
 usingBlock:^(NSNotification *note) { 
 
 static dispatch_once_t onceToken; 
 dispatch_once(&onceToken, ^{ 
 
 SEL setcategory = @selector(setCategory:withOptions:error:); 
 SEL newsetcategory = @selector(newsetCategory:withOptions:error:); 
 
 Method originalMethod = class_getInstanceMethod([self class], setcategory); 
 Method extendedMethod = class_getInstanceMethod([self class], newsetcategory); 
 method_exchangeImplementations(originalMethod, extendedMethod); 
 }); 
 
 }]; 
 return self; 
 }
 
 @end
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 Bill-Ape · Feb 22, 2017 at 04:27 PM 0
Share

Thanks for this. It worked for us, but was crashing on iOS 9.3.4, I think because the original AVAudioSession init method wasn't being called. Have added our own solution based on yours as an answer here too.

avatar image
1

Answer by Bill-Ape · Feb 22, 2017 at 04:25 PM

Based on @lanestp's answer, we were finding iOS 9.3.4 was crashing with this. So we modified it thus and it worked. Thanks

 #import <UIKit/UIKit.h>
 #import <AVFoundation/AVFoundation.h>
 #import <objc/runtime.h>
 
 @implementation AVAudioSession(UnityStartupVolumeFix)
 
 - (BOOL)altSetCategory:(NSString *)category withOptions:(AVAudioSessionCategoryOptions)options error:(NSError * _Nullable *)outError
 {
     options = AVAudioSessionCategoryOptionMixWithOthers;
     return [self altSetCategory:category withOptions:options error:outError];
 }
 
 + (void)load
 {
     AVAudioSession* instance = [AVAudioSession sharedInstance];
     static dispatch_once_t avAudioSessionHackOnce;
     dispatch_once(&avAudioSessionHackOnce, ^{
         SEL setCategorySelector = @selector(setCategory:withOptions:error:);
         SEL altSetCategorySelector = @selector(altSetCategory:withOptions:error:);
         Method originalMethod = class_getInstanceMethod([instance class], setCategorySelector);
         Method extendedMethod = class_getInstanceMethod([instance class], altSetCategorySelector);
         method_exchangeImplementations(originalMethod, extendedMethod);
     });
 }
 
 @end
 
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 pmaloka · Sep 07, 2016 at 06:32 PM

@tinklife, @thorn-erikson This is a known issue. Please upvote so they fix it sooner.

https://issuetracker.unity3d.com/issues/ios-sound-volume-of-music-playing-on-the-device-gets-quiet-after-launching-a-unity-app

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

7 People are following this question.

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

Related Questions

Getting iOS device volume 1 Answer

what audio.volume level on iphone would match the music player volume? 1 Answer

DSPBuffer Size from script 1 Answer

Math formula to set volume levels nicely 0 Answers

Audio not coming out of speakers 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