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 (36)

  1. 8c06310c537108165b451a89282e56ce?d=mm

    Morgan

    Nov 03, 2016 14:53

    p2 and p3 have been released, still with no fix apparently. Any further details on a workaround would be great!

  2. 8c06310c537108165b451a89282e56ce?d=mm

    Morgan

    Oct 24, 2016 16:33

    Patch 5.4.2p1 is out but no mention of this being fixed :( It's over a year since I've been able to ship an update to my app due to one shipstopper bug overlapping another :(

  3. 8c06310c537108165b451a89282e56ce?d=mm

    Morgan

    Oct 21, 2016 21:35

    Thanks, LaneSTP! What's the path to Plugins/iOS? Maybe I need to create it? (There's no Plugins folder in either the Unity project or the Xcode project.)

    Any need to then call/reference/select the created file? Or is its existence enough?

  4. F0dded27025f0fe56bc3a827a18cfdaa?d=mm

    lanestp

    Oct 21, 2016 02:15

    For everyone trying to fix this issue just create a AudioFix.mm file in Plugins/iOS/ and copy paste the code in there

  5. 8c1639b8233efb793b8b7aa4522aaf5a?d=mm

    lEscargotl

    Oct 12, 2016 22:42

    @lanestp I guess you need to buy the UIKit plugin ($25) for that fix?

  6. 8c1639b8233efb793b8b7aa4522aaf5a?d=mm

    lEscargotl

    Oct 12, 2016 22:14

    @lanestp Can you explain what "Just include this code in your plugin." means? If I copy-paste that code, where should it go?

  7. 8c06310c537108165b451a89282e56ce?d=mm

    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.

  8. 8c06310c537108165b451a89282e56ce?d=mm

    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).

  9. 826da7cf789a148d329130a527bf790e?d=mm

    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.

  10. F0dded27025f0fe56bc3a827a18cfdaa?d=mm

    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

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.