Pause game music when video ad running (613734)

I want to pause my background music when my device running video ads. For this stuff, I have written this code.

    void OnApplicationPause (bool pause)
     {
         Debug.Log("pause : " + pause);
         if(pause)
             SoundManager.Instance.PauseGameMusic();
         else
             SoundManager.Instance.PlayGameMusic();
     }

But in my iphone, this code is not working at all. Basically my goal is to pause game music at the time of video playback.

Please give me some suggestion for this.

You can use AudioListener.pause to pause all sounds in the scene. You can also selectively ignore this state by setting AudioSource.ignoreListenerPause on the appropriate sources, if needed. I think this will work for you.

Thanks for your reply but at present I can’t able to recognise event when to call AudioListener.pause.
Because OnApplicationPause method is not getting called at all in iPhone device.

OnApplicationPause() is called when the Unity player is paused by something, like the game window losing focus, I believe. I don’t have any experience with Unity on iPhone, but are you sure that the player is being paused? How are the video ads inserted?

This problem I resolved from programming side.
When ad show code is executing at that time I am pausing game music and when ad close even it triggered at that time again I am playing game music. that’s it :slight_smile: