Search Unity

Audio Unity iOS default audio session category.

Discussion in 'Audio & Video' started by Novi-Novi, Sep 20, 2017.

  1. Novi-Novi

    Novi-Novi

    Joined:
    Jun 12, 2017
    Posts:
    2
    I'm trying to make my iOS app not mute audio from other apps for example if the user is playing music and opens my app, the music will continue playing.

    I have tried setting the audio session category to AVAudioSessionCategoryPlayback with the option AVAudioSessionCategoryOptionMixWithOthers.

    More precisely, I have made a plugin with the following code:

    #import <UnityAppController.h>
    #import <AVFoundation/AVFoundation.h>

    @interface IgnoreMuteSwitch : UnityAppController

    -(void) SetAudioSessionCategory;

    @End

    @implementation IgnoreMuteSwitch

    -(void) startUnity: (UIApplication *) application
    {
    [super startUnity:application];
    [self SetAudioSessionCategory];
    }

    -(void) SetAudioSessionCategory
    {
    AVAudioSession *session = [AVAudioSession sharedInstance];
    [session setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryMixWithOthers error:Nil];
    [session setActive:YES error:Nil];
    }

    @End

    IMPL_APP_CONTROLLER_SUBCLASS(IgnoreMuteSwitch);

    The problem is that this only works if the user starts playing music after my app has already loaded. It seems that Unity upon starting will set the audio session category to AVAudioSessionCategorySoloAmbient whose behaviour includes muting audio from other apps. So by the time my bit of code runs, the music would have already been paused and will not unpause until the user do it themselve.

    My question is how do I tell Unity to default to a different audio session category on start up?
     
  2. daisoto

    daisoto

    Joined:
    Mar 28, 2020
    Posts:
    6
    Hello, have you solved this problem?