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

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

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

  3. D91b27f903a0377edfe9429ae7819224?d=mm

    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.

  4. D91b27f903a0377edfe9429ae7819224?d=mm

    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.

  5. 5899ec41dddaa66045c210f88808fa63?d=mm

    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.

  6. 82e2e7f65eb6c816ce99792e7e352018?d=mm

    Davee

    Sep 08, 2016 07:48

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

  7. 5899ec41dddaa66045c210f88808fa63?d=mm

    pmaloka

    Sep 07, 2016 02:42

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

  8. 5899ec41dddaa66045c210f88808fa63?d=mm

    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.