iOS Audio Ads in Background

621 views
Skip to first unread message

Joshua Moore

unread,
Mar 18, 2021, 6:47:15 PM3/18/21
to Interactive Media Ads SDK
Hi Team,

We are using the IMA SDK for iOS to play VAST audio ads. We are able to request ads using the IMAAdsLoader and play them when the app goes into the background but issues arise when an ad ends while in the background. It seems as though the .COMPLETE event that we are expecting is not sent until the app enters the foreground, even though this event can be observed from an SSL proxy. 

I have double checked that my implementation follows the suggestions in the documentation on background playback by enabling Audio and CarPlay in background modes, setting my AVAudioSession's category to AVAudioSessionCategoryPlayback, and setting enableBackgroundPlayback to TRUE in the settings of my instance of IMAAdsLoader. I have also tried calling play() on my content player before requesting ads and calling resume() on my IMAAdsManager after entering the background. 

This issue seems to be present on older versions of the SDK and appears when I use test VAST resources from iabtechlab.com. I have also tried testing this same scenario using the IMA Video Suite Inspector using one of the default VAST ads and I'm seeing the same issue.

 This could be an unrelated issue but I noticed that the IMA logs for VAST events in Xcode's debugger seem to be delayed when the app is in the background. 

Are there plans to resolve this in another release? If not, is there a workaround that I can implement? 

Thanks,

Joshua Moore

IMA SDK

unread,
Mar 18, 2021, 11:16:16 PM3/18/21
to joshua...@entercom.com, ima...@googlegroups.com

Hi Joshua,

Thank you for bringing this issue to our attention.

Could you tell us what IMA SDK for iOS version you are using here? I saw cases reported to us related to audio ads issues while in the background. Thus, just to verify if this is similar to those cases, could you also share a screen recording of the behavior that you are seeing for our reference?

 

Regards,



Google Logo
Sherwin Diesta
IMA SDK Team
 

 

ref:_00D1U1174p._5004Q2Dwy3x:ref

Joshua Moore

unread,
Mar 19, 2021, 12:41:15 PM3/19/21
to Interactive Media Ads SDK
Hi. Sherwin,

Thanks for the quick response.

We are using v3.13.0 and I have also tested this using v 3.14.1. We have seen the issue on most (if not all) iOS versions we support but have explicitly tested using 12.4.1, 12.4.3, 13.0, 13.1.2 and 14.4.
I've attached a video. showing what happens when the app goes into the background during/before ad playback.

Thanks,

Joshua Moore

RPReplay_Final3.mov

IMA SDK

unread,
Mar 19, 2021, 2:12:47 PM3/19/21
to joshua...@entercom.com, ima...@googlegroups.com
Hi Joshua,

I work with Sherwin and will assist you. Thank you for the video, there have been similar reports about this issue. For us to investigate further we will need a diff from our Basic Example including the recommendations Apple gives for backgrounding the AVPlayer, changes added in our guide to Background Audio Playback and minimum other modifications to address your use case.
Regards,

Google Logo
Aryeh Baker
IMA SDK Team
 


ref:_00D1U1174p._5004Q2Dwy3x:ref

Joshua Moore

unread,
Mar 22, 2021, 11:58:34 AM3/22/21
to Interactive Media Ads SDK
Hi Aryeh,

I was able to identify the differences between our implementation and those three resources.

 The steps we took to enable background audio playback are almost identical to Apple’s documentation for backgrounding the AVPlayer. The only difference is that we are not setting the AVAudioSession’s mode at all after setting its category to .playback. We are not playing video content so a large part of that document does not apply to our implementation.

As for the IMA documentation on background playback, the only differences I have found relate to the two callouts in the “Important” section. We are not calling [IMAAdsManager resume] as we are not using video playback. Audio playback continues to play once the app enters the background. During testing I attempted to manually call play() on the content player and saw no change to behavior. This could be because we are already able to successfully make requests from the SDK.

When diffing the Basic Example project in swift, I found that we are setting our IMAAdsLoader’s enableBackgroundAudio and disableNowPlayingInfo settings to true. The only other difference is that we do not include adsRenderingSettings.linkOpenerPresentingController = self in adsLoader(adsLoadedWith).

These are the only differences that I found across the three suggested resources. Please let me know if more info is needed.

Thanks,

Joshua Moore

IMA SDK

unread,
Mar 22, 2021, 3:51:27 PM3/22/21
to joshua...@entercom.com, ima...@googlegroups.com
Hi Joshua,

I brought your comments up to the rest of my team, we will get back to you as soon as possible.

Joshua Moore

unread,
Apr 1, 2021, 4:51:19 PM4/1/21
to Interactive Media Ads SDK
Hi Aryeh, 

Are there any updates on whether this issue is something that will be fixed in coming releases? 

Thanks,

Joshua Moore

IMA SDK

unread,
Apr 2, 2021, 9:05:19 AM4/2/21
to joshua...@entercom.com, ima...@googlegroups.com
Hi Joshua,

Thank you for reaching back out to us. I have looked to see if their has been any feedback from our team. They have given some feedback. One of the basic ones is that it would appear that what is being seen is in fact what you would expect and that it is due to some things that Apple has as far as allowing ads to be played in the background. We do have a few suggestions that could help to reduce the issue.
  • Which over to our PAL SDK which will give you more control over the ad loading.
  • You could also run the Native JS in a JSContext
But in general you will most of the time see throttling or delays in things happening as the background, if non audio. Is the main reason for most of this issue. From what I have been reading on the feedback. The PAL seems to be your best solution.

Regards,
Google Logo
William Pescherine
IMA SDK Team
 


ref:_00D1U1174p._5004Q2Dwy3x:ref

Joshua Moore

unread,
Apr 6, 2021, 6:20:17 PM4/6/21
to Interactive Media Ads SDK
Hi William, 

Thank you for the suggestions on solutions here. I was able to implement the PAL SDK and receive valid nonces. However, I am not sure how this replaces ad requests with the IMA SDK. Our issue seems to be related more to receiving ad cue point notifications from IMA rather than sending out info about ad interactions. Does the team have any other suggestions for our situation on iOS, playing audio-only ads?

Best,

Joshua Moore

IMA SDK

unread,
Apr 7, 2021, 2:02:32 AM4/7/21
to joshua...@entercom.com, ima...@googlegroups.com

Hi Joshua,

Thank you for reaching back to us. I’ve been looking for feedback on our team and it appears that they are still extensively working for the best solution to apply for this behaviour. For other solutions you’re requesting, let me bring this up to my team to talk about it and I will get back to you once I have their response.


Regards,

Google Logo
Sherwin Diesta
IMA SDK Team
 


ref:_00D1U1174p._5004Q2Dwy3x:ref

Joshua Moore

unread,
May 4, 2021, 7:32:32 PM5/4/21
to Interactive Media Ads SDK
Hi Sherwin, 

I'm curious if there has been a solution to the background ad resumption issue? I saw that there was a new version released yesterday but did not see a change in behavior. 

Thanks,

Joshua Moore

IMA SDK

unread,
May 4, 2021, 9:44:28 PM5/4/21
to joshua...@entercom.com, ima...@googlegroups.com

Hi Joshua,

 

I work with Sherwin.

 

It seems like we have not received feedback from the team regarding this issue but I already asked for an update on your behalf. For the meantime, keep an eye on our latest releases for possible updates.

Regards,

Google Logo
Michael Angelo Legaspi
IMA SDK Team
 


ref:_00D1U1174p._5004Q2Dwy3x:ref

Joshua Moore

unread,
Jul 20, 2021, 9:49:52 AM7/20/21
to Interactive Media Ads SDK
Hi Team,

Update: I was able to upgrade to version 3.14.4 that "Fixed an issue that caused missing events when apps are backgrounded." 

I am no longer seeing this issue in the most recent version of the iOS SDK. I am able to begin playback of an ad, background or lock the device and receive the correct "complete" event.

Thank you for the work on this fix,

Joshua Moore

Joshua Moore

unread,
Aug 5, 2021, 4:12:56 PM8/5/21
to Interactive Media Ads SDK

Hi Team,

Our QA team has discovered more issues related to ad playback while our app is in the background. 

1. When beginning an ad in the background, fetch requests using IMAAdsRequest (initialized with either adTagUrl or adsResponse) succeed when the app is in the background with the following logs:

  • 2021-08-05 11:37:17.621148-0600 {App-Name}[21512:11262776] Core: (INFO) ima.loader.AdSourceFactory: Creating VastAdSource.
  • 2021-08-05 11:37:17.625164-0600 {App-Name}[21512:11262776] Core: (INFO) VastAdSource: processInlineAd, successCallback with 1 ads

After getting these success messages, the IMAManager does not begin ad playback and outputs the following:

  • 2021-08-05 13:59:03.544634-0600 {App-Name}[21549:11282222] Core: (INFO) ima.vast.VideoAdEventTracker: dispatching event mediaLoadTimeout
  • 2021-08-05 13:59:05.544542-0600 {App-Name}[21549:11282222] Core: (INFO) ima.admanager.VideoAdManager: Playback error: [object Object] AdError 402: VAST media file loading reached a timeout of 8 seconds.
  • 2021-08-05 13:59:07.546325-0600 {App-Name}[21549:11282222] Core: (WARNING) ima.common.ErrorUtils: Error play dispatched: AdError 402: VAST media file loading reached a timeout of 8 seconds.


2. When an ad begins in the foreground and the app is put into the background, ____ tend to get delivered more slowly than usual. Non-ad content does not begin afterwards because the "complete" is never sent. This prevents the IMA SDK from triggering adsManager(didReceive event). The logs appear as follows:

  • 2021-08-05 14:00:56.164982-0600 {App-Name}[21549:11282222] Core: (INFO) ima.loader.AdSourceFactory: Creating VastAdSource.
  • 2021-08-05 14:00:56.169273-0600 {App-Name}[21549:11282222] Core: (INFO) VastAdSource: processInlineAd, successCallback with 1 ads
  • 2021-08-05 14:00:57.069756-0600 {App-Name}[21549:11282222] Core: (INFO) ima.vast.VideoAdEventTracker: dispatching event impression
  • 2021-08-05 14:00:58.540258-0600 {App-Name}[21549:11282222] Core: (INFO) ima.vast.VideoAdEventTracker: dispatching event creativeView
  • 2021-08-05 14:01:00.539994-0600 {App-Name}[21549:11282222] Core: (INFO) ima.vast.VideoAdEventTracker: dispatching event start
  • 2021-08-05 14:01:01.539950-0600 {App-Name}[21549:11282222] Core: (INFO) ima.vast.VideoAdEventTracker: dispatching event measurable_impression
  • 2021-08-05 14:01:09.539382-0600 {App-Name} 21549:11282222] Core: (INFO) ima.admanager.VideoAdManager: Playback error: AdError 202: VAST media file duration differs from the VAST response duration by 30.00 seconds.
  • 2021-08-05 14:01:09.539482-0600 {App-Name}[21549:11282222] Core: Exception text: AdError 202: VAST media file duration differs from the VAST response duration by 30.00 seconds.
  • 2021-08-05 14:01:11.539555-0600 {App-Name}[21549:11282222] Core: (INFO) ima.vast.VideoAdEventTracker: dispatching event firstQuartile
  • 2021-08-05 14:01:15.538533-0600 {App-Name}[21549:11282222] Core: (INFO) ima.vast.VideoAdEventTracker: dispatching event midpoint
  • 2021-08-05 14:01:19.540092-0600 {App-Name}[21549:11282222] Core: (INFO) ima.vast.VideoAdEventTracker: dispatching event thirdQuartile

No other output is received until the app is brought back to foreground. 


Additional information:

IMAAdsRequest configuration:

  • adDisplayContainer: assigned on init
  • contentPlayhead: assigned on init
  • userContext: nil on init
  • vastLoadTimeout set to 10000.0
  • used in adsLoader.requestAds(with:)
IMAAdsLoader configuration:

  • initialized with IMASettings
    • enableBackgroundPlayback: true
    • disableNowPlayingInfo: true
    • enableDebugMode: true
  • delegate is set
IMAAdsManager configuration

  • initially retrieved from IMAAdsLoadedData.adsManager
  • initialized with IMAAdsRenderSettings()
  • delegate is set

Is there still a fix in the pipeline to handle ad playback on the iOS SDK in a background state?
Please let me know if more information is needed. 

Thanks,


Joshua Moore

IMA SDK

unread,
Aug 6, 2021, 3:16:39 AM8/6/21
to joshua...@entercom.com, ima...@googlegroups.com

Hi Joshua,

 

Thank you for getting back to us.

 

For your first scenario, this doesn't work because the content must already be playing before the app is backgrounded, not after. It's just that when you move to the background, iOS will pause the player, so you must manually call play on it again when that happens, to avoid a pause.

 

For the other query, I have raised this to the rest of the team and we will update you once they have responded.

Regards,

Joshua Moore

unread,
Aug 18, 2021, 4:11:45 PM8/18/21
to Interactive Media Ads SDK
Hello, 

Thanks the information. 
Just to confirm, are you saying that starting ads while playback is happening in the background is not something that is supported at the moment? 

I was able to narrow down that place at which this issue is occurring. 

It seems as though requests are completing correctly and I am getting calls on both adsManager(didReceive event: ) with a .LOADED event type. I am also getting a call on adsManagerDidRequestContentPause. 

Nothing happens when I call adsManager.start() or adsManager.resume() when the app is in background. 

Confirmation of my first statement would probably explain the behavior I am experiencing. If this feature is not currently supported, are there alternatives that you know of? 

IMA SDK

unread,
Aug 19, 2021, 1:28:39 AM8/19/21
to joshua...@entercom.com, ima...@googlegroups.com

Hi Joshua,

 

To clarify, it is recommended that your content is already playing before requesting ads in the background, since otherwise iOS will most likely not let new video playback start in the BG if there currently is none. If the content is paused, and you try to request ads in the background, it will most likely fail.
 

On the other hand, for your other query before regarding if there is still a fix in the pipeline to handle ad playback on the iOS SDK in a background state, a fix for that is now live.

 

Please let us know if you still encounter any issues.

Regards,

Joshua Moore

unread,
Aug 19, 2021, 11:36:08 AM8/19/21
to Interactive Media Ads SDK
Hello,

Thanks for the quick response. 

For a bit more clarity, my issue is happening when I already have playback in the background. 

Our main player does not conform to AVPlayer so we pass a separate AVPlayerObject into the IMAAVPlayerContentPlayhead on init. This has not caused an issue during playback in the foreground but I am wondering if this is something that is causing the problem with initiating playback.

Another point is that we are using this for audio-only playback. Are you aware of any modifications that are needed for that?

I am currently using v 3.14.4 so I should be consuming the background playback updates. 

Thank you for the consistent help here. This seems like a difficult issue to track down. 

IMA SDK

unread,
Aug 20, 2021, 1:00:58 AM8/20/21
to joshua...@entercom.com, ima...@googlegroups.com

Hi Joshua,

 

Thank you for your response.

 

Are you seeing the same current behavior using our sample apps? I believe as long as you have followed the guide on background audio playback, there are no others needed to be modified. It would be a lot of help if you could send us a sample project implementation where we could replicate the issue and/or a screen recording of the current behavior.

Regards,

Joshua Moore

unread,
Aug 20, 2021, 11:18:30 AM8/20/21
to Interactive Media Ads SDK
I have been using the sample apps to test this and I was only seeing the behavior or not returning to playback after an ad. 

I am going through the background audio playback guide again to see if I missed anything. There seems to be something to calling resume on the IMAAdsManager when the app goes to the background. My original thought there was that it was not needed because playback had not stopped by that point.

 I am also setting up a timer to see if I can mimic the behavior of "complete" notification based on the returned ad duration since I am not getting that back when the app is in the background. 

I will keep this thread updated with my findings.

IMA SDK

unread,
Aug 20, 2021, 12:55:28 PM8/20/21
to joshua...@entercom.com, ima...@googlegroups.com
Hi Joshua,

Thank you for responding back to us. I have looked at what our team has said about this. It would appear that this should be fixed now. If you update to 3.14.4 it should help to resolve this. If you still have issues after this, please let us know and we will look to see what's happening.

Regards,
Google Logo
William Pescherine
IMA SDK Team
 


ref:_00D1U1174p._5004Q2Dwy3x:ref

Joshua Moore

unread,
Aug 25, 2021, 7:26:05 PM8/25/21
to Interactive Media Ads SDK

Hello William, 

Thank you and the rest of the team for the help here. I am now able to consistently begin playback in the background.

I am still in a situation where a timer on my side is still necessary to return to content playback but this is not a problem at this time. 

Best,

Joshua Moore
Reply all
Reply to author
Forward
0 new messages