Search Issue Tracker

Fixed in 5.5.0

Votes

65

Found in

5.3.6p4

Issue ID

828762

Regression

Yes

[iOS] Sound volume of music playing on the device gets quiet after launching a Unity app

iOS

-

When a Unity app is launched, any audio playing on the device (iTunes, Spotify, etc.) gets quiet, even when the app is not playing any sounds. This issue does not occur when 'Disable Unity Audio' is checked in Edit > Project Settings > Audio. When the app goes back to background or is exited, the sound goes back to normal.

Steps to reproduce:
1) Create a new project.
2) Build for iOS.
3) Play music on a device.
4) Launch the build on the device.

As soon as the app starts, the sound volume is halved.

Reproduced on:
5.5.0b2, 5.4.0p4, 5.3.6p4

Did not reproduce:
5.2.4f1

Comments (40)

  1. Morgan

    Oct 09, 2016 22:41

    Same thing in 5.4.1p4 also. The workarounds mentioned are greek to me—any tips?

    My app has been waiting a year without an update because of one ship-stopper bug after another in the Unity engine :( I fear my users won't have that much patience. Unity 5.3 has one bug, requiring 5.4 to fix... but 5.4 has this bug! I have to pick which bug to add to my app or I can't update it.

  2. Morgan

    Oct 04, 2016 00:21

    Same here - my project never had "Prepare for iOS Recording" selected (nor "Override iPod Music") but when I went from Unity 5.3 to 5.4, I now see this problem on all devices and OS versions. Music app is affected, and so are third-party audio apps (like Overcast for podcasts).

    My app is a productivity app that people will use while "doing whatever"--like phone calls, podcasts, and music, so this annoyance is a dealbreaker. Users will complain!

    The problem persists as of at least 5.4.1p3 (the latest).

  3. tim-bluenose

    Sep 28, 2016 22:14

    Confirmed we are seeing this too. Has been happening since we upgraded from 5.2 to 5.4.

    We do NOT have "Prepare for iOS Recording" selected in our builds, but the problem persists. Bonus if it works for you, but it does not seem like that is a global fix.

  4. lanestp

    Sep 28, 2016 22:10

    Here's my fix. Just include this code in your plugin.

    #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

  5. the-Grumbleputty

    Sep 21, 2016 16:51

    Ok, the fix in my case was suspiciously easy...I just turned off the "Prepare IOS for Recording" button in Player Settings. My app still records audio, but now plays sound back properly. If you're having the same problem, hopefully the solution that worked for me will help you too.

  6. the-Grumbleputty

    Sep 21, 2016 16:46

    Pretty much destroys my game project, which lets the players record their names and calls on them during play. Once again regretting updating Unity.

  7. pmaloka

    Sep 08, 2016 11:26

    I came up with a workaround. As they say, "Necessity is the mother of invention."

    1) Subclassed AppDelegate
    2) Inside subclassed startUnity, swizzled [AVAudioSession setCategory:withOptions:error:]
    3) Make swizzled version change option AVAudioSessionCategoryOptionDuckOthers to AVAudioSessionCategoryOptionMixWithOthers

    Seems to work for now. Hoping Unity will provide a better sanctioned way to solve this.

  8. Davee

    Sep 08, 2016 07:48

    Also seeing this issue, which probably will prevent us from updating Unity.

  9. pmaloka

    Sep 07, 2016 02:42

    What is the workaround for this issue? (Severity 3 - workaround is possible).

  10. pmaloka

    Sep 07, 2016 02:39

    We are seeing this as well. We need audio to play normally so that users can still talk on the phone at normal volumes while playing our casual game.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.