Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

AVAudioSessionCategory not working with Microphone

Discussion in 'iOS and tvOS' started by doggan, Jan 28, 2016.

  1. doggan

    doggan

    Joined:
    Aug 12, 2012
    Posts:
    23
    Hello.

    I'm building a media-focused app with Unity. As per the Apple guidelines (https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/Sound.html), sound is essential to the app, so I am trying to change the AVAudioSession category so that my app plays sound even when in 'silent' mode.

    I am able to hook into the view controller, and get it working with this:

    Code (CSharp):
    1. - (void)viewWillAppear:(NSNotification*)notification
    2. {
    3.     AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    4.     [audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
    5. }
    However, as soon as I use the Unity Microphone to record audio, the above setCategory seems to be invalidated, and my app once again goes into silent mode until I disable the 'silent' switch.

    Is the Unity Microphone implementation overriding the category? I've tried using other categories (AVAudioSessionCategoryMultiRoute, etc), but as soon as the Microphone is used, my setting gets clobbered.

    Thanks.

    edit: I 'solved' this by explicitly setting the category on app startup as well as AFTER I finish recording with the microphone.
     
    Last edited: Jan 28, 2016
  2. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,602
    well, if you read apple docs you picked totally wrong setting. Did you try AVAudioSessionCategoryPlayAndRecord instead of AVAudioSessionCategoryPlayback? There might be some issues in unity internally, but for now it looks like user error
     
  3. doggan

    doggan

    Joined:
    Aug 12, 2012
    Posts:
    23
    Yep, I was using AVAudioSessionCategoryPlayAndRecord originally, but it was still getting clobbered. I also noticed the volume (even at max setting) was noticeably more quiet than usual.

    Using AVAudioSessionCategoryPlayback put my app at the same volume level as all other apps, and since I have to explicitly call it after microphone recording anyways due to the clobbering issue, this was the setting I chose.
     
  4. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,602
    that sounds weird. Well, if go by the docs, than sure enough AVAudioSessionCategoryPlayback is for playback *only* (no mic support).
    "but it was still getting clobbered" can you elaborate what does that mean? you essentially fallback to "normal" category?
    can you please create small repro project and bug report it?
    Essentially FMOD goes through CoreAudio so maybe there is some weird interop issue with AVAudioSession.
    P.S. I'm going on vacation naow so if you DO create bug report with repro i will be able to look into it in a week