Search Unity

Question ironSource SDK mutes sounds after playing an ad on iOS

Discussion in 'iOS and tvOS' started by hrkm, Mar 15, 2023.

  1. hrkm

    hrkm

    Joined:
    Oct 21, 2013
    Posts:
    13
    Hi, I have integrated with the ironSource SDK for playing rewarded video ads. It works perfectly fine on Android.

    However, when deployed on iOS, it will play the ad with sound, but once you exit the ad experience all sounds are gone / muted.

    Pressing home and coming back to the game restores the sounds.

    While I do have "mute/unmute" logic for playing ads (mute when you start playback, unmute when finished), I don't trigger that on "resuming" from home. And simply using a toggle that would invoke that logic in the game doesn't do a thing, which makes me think it's ironSource SDK / iOS doing something funky with audio.

    Has anyone else experienced this? How did you solve it?

    I made sure that "mute other audio sources" is unchecked in the player settings, since that was the only search result that seemed related, but it didn't help.
     
    melgeorgiou, yuki_goto and AndreaMar like this.
  2. AndreaMar

    AndreaMar

    Joined:
    Oct 29, 2019
    Posts:
    35
    Hi. I had the same problem. However I've resolved it by unchecking that box in the player settings for iOS. Are you sure you've deselect the "mute other audio sources" for the specific platform you're testing on?
     
  3. hrkm

    hrkm

    Joined:
    Oct 21, 2013
    Posts:
    13
    Yes, I have deselected that for iOS build settings. Didn't look at Android one. And this is the checkbox in the Unity Editor itself, not Xcode, right? Or is there another one in Xcode project to uncheck?
     
  4. AndreaMar

    AndreaMar

    Joined:
    Oct 29, 2019
    Posts:
    35
    In the Unity editor. Project settings -> Player settings -> iOS -> Other settings -> Uncheck "Mute other audio sources"

    This just worked for me.

    I'm also setting the AudioListener.volume to 0 when the ad is opened and to 1 when it's closed, and I'm notifying the IronSource agent when the application is paused/unpaused (I guess this has something to do with it).

    Code (CSharp):
    1. private void OnApplicationPause(bool isPaused)
    2.     {
    3.         IronSource.Agent.onApplicationPause(isPaused);
    4.     }
     
  5. hrkm

    hrkm

    Joined:
    Oct 21, 2013
    Posts:
    13
    I do have that OnApplicationPause exactly like you. I also have the following:

    Code (CSharp):
    1. private void IronSourceEvents_onRewardedVideoAdShowFailedEvent(IronSourceError obj)
    2.     {
    3.         StaticAudioSource.SetMute(false);
    4.     }
    5.  
    6.     private void IronSourceEvents_onRewardedVideoAdOpenedEvent()
    7.     {
    8.         StaticAudioSource.SetMute(true);
    9.     }
    10.  
    11.     private void IronSourceEvents_onRewardedVideoAdClosedEvent()
    12.     {
    13.         StaticAudioSource.SetMute(false);
    14.     }
    With the SetMute function looking like this:

    Code (CSharp):
    1. public static void SetMute(bool mute)
    2.     {
    3.         StaticAudioSource.AudioSource.mute = MuteAllSounds || mute;
    4.         StaticAudioSource.BackgroundMusicAudioSource.mute = MuteAllSounds || mute;
    5.     }
    And then this is what I use to play the ads:
    Code (CSharp):
    1. if (IronSource.Agent.isRewardedVideoAvailable())
    2.         {
    3.             StaticAudioSource.SetMute(true);
    4.             IronSourceEvents.onRewardedVideoAdRewardedEvent += IronSourceEvents_onRewardedVideoAdRewardedEvent;
    5.             IronSource.Agent.showRewardedVideo("IAP_Store");
    6.         }
    If I didn't do the SetMute call, the game audio would be still playing. Arguably I think I can remove the one in the last code block, since it should also be covered by the onRewardedVideoAdOpenedEvent.

    Nothing else calls the SetMute function anywhere in my code. Am I missing some special case / event from ironSource?
    But then why would it restore itself when I switch to home and back into the game?

    Are you saying that the onApplicationPause should mute the sounds as well? I don't think it did that for me on Android previously, I can give it a try though.
     
  6. AndreaMar

    AndreaMar

    Joined:
    Oct 29, 2019
    Posts:
    35
    No, onApplicationPause doesn't mute the sound, unless you specifically tell it do it. But since, on iOS, if you exit and come back again to the app the sound restarts, then maybe it has something to do with it. Also because the IronSource docs are asking for that piece of code, so...

    I'm muting and unmuting the audio only on -VideoAdOpened and -Closed delegates. Is it necessary for VideoAdShowFailedEvent as well? Maybe because you're muting it before calling it, right?

    I honestly don't know what's going on with IronSource. It does the same with interstitial ads too. Delegates are being called. Just the audio is not working, so it must be some app settings like that unchecked box that is now working for me.

    Your code setup seems pretty similar to mine from what I see. Try using the AudioListener.volume to mute all audios in scene if you can. I don't really have a reason for that change (apart from convenience) but that's working for me.
     
  7. AndreaMar

    AndreaMar

    Joined:
    Oct 29, 2019
    Posts:
    35
    What if you try to force or simulate the app via code to become active? Like when you put it on background and then in foreground again. I never tried to do it, so I don't really know if it's possible. If not, you can still try to debug it by listening to all delegates for the application status change. Maybe IronSource is changing that.
     
  8. hrkm

    hrkm

    Joined:
    Oct 21, 2013
    Posts:
    13
    Here are changes I made:
    - upgraded Unity to 2021.3.21f1 (used 2021.3.14f1 previously)
    - upgraded Firebase to 10.6 (from 10.3) - which is probably unrelated
    - removed the ```StaticAudioSource.SetMute(true);``` from the code just before playing the ad (the last snippet from comment #5)

    And it works now as expected.

    I suspect that possibly there was some race condition, or a bug in previous version of unity as the root cause, but I wasn't able to debug it otherwise (I'm using a very very old macbook and debugging any code on it is just taking way too long to bare, so I'm glad that one of the three steps above helped)
     
    AndreaMar likes this.
  9. sunil_unity240

    sunil_unity240

    Joined:
    Nov 1, 2022
    Posts:
    3
    Pause Game
    The API setPauseGame is introduced as part of the ironSource Unity SDK 7.2.4, and is relevant for iOS apps only.

    When setting your PauseGame status to “true”, all your Unity 3D game activities will be paused (Except the ad callbacks). The game activity will be resumed automatically when the ad is closed.

    You should call the setPauseGame API once in your session, before or after initializing the ironSource SDK, and as it affects all ads (Rewarded Video and Interstitial ads) in the session.

    >> below the code Add it your game it will work in ios


    public void Start()
    {
    IronSource.Agent.SetPauseGame(true);
    }
     
  10. wh_dev

    wh_dev

    Joined:
    Oct 16, 2022
    Posts:
    4
    Is SetPauseGame(true) meant to be called once on app start as a 'setting' of the SDK for it to automatically take care of muting ingame audio during ads in iOS just as it does on Android? Or is it meant to be called everytime right before an ad is shown and then SetPauseGame(false) when the ad was closed? The documentation suggests option 1, but why is that not default behaviour then?
     
    passionpuncher and francisIsFine like this.
  11. francisIsFine

    francisIsFine

    Joined:
    Jun 26, 2018
    Posts:
    40
    I'm having this problem too. None of the fixes above have worked. On top of the audio not coming back, some of touch input settings get messed up too. It's after I put the app in the background and come back that the everything resumes back to normal. Anybody else found a different solution?
     
  12. francisIsFine

    francisIsFine

    Joined:
    Jun 26, 2018
    Posts:
    40
    Just following up. It seems in my case, the problem was happening when the interstitial suddenly appears at the exact time as a sound effect is triggered. Likewise, it seemed the touch input was also getting interrupted (ad appearing before the touch reaches its end phase), and so it wasn't being allowed to recover/reset. Delaying the launch of the interstitial solved it for me.

    The solution posted here worked for the audio problem too, but you'd have to re-apply your player's sound preferences each time.