Skip to content

Commit a01866d

Browse files
[interactive_media_ads] Adds support for time offsets of ad breaks (#9953)
Fixes flutter/flutter#174405 ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent 1a10936 commit a01866d

29 files changed

+202
-112
lines changed

packages/interactive_media_ads/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.2.7
2+
3+
* Adds support to retrieve content time offsets at which ad breaks are scheduled. See
4+
`AdsManager.adCuePoints`
5+
16
## 0.2.6+7
27

38
* Updates Android `PlatformAdDisplayContainer` implementation to support preloading ads.

packages/interactive_media_ads/android/src/main/kotlin/dev/flutter/packages/interactive_media_ads/AdsManagerProxyApi.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class AdsManagerProxyApi(override val pigeonRegistrar: ProxyApiRegistrar) :
2626
pigeon_instance.start()
2727
}
2828

29-
override fun getAdCuePoints(pigeon_instance: AdsManager): List<Double> {
29+
override fun adCuePoints(pigeon_instance: AdsManager): List<Double> {
3030
return pigeon_instance.adCuePoints.map { it.toDouble() }
3131
}
3232

packages/interactive_media_ads/android/src/main/kotlin/dev/flutter/packages/interactive_media_ads/AdsRequestProxyApi.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class AdsRequestProxyApi(override val pigeonRegistrar: ProxyApiRegistrar) :
2121
*
2222
* This must match the version in pubspec.yaml.
2323
*/
24-
const val pluginVersion = "0.2.6+7"
24+
const val pluginVersion = "0.2.7"
2525
}
2626

2727
override fun setAdTagUrl(pigeon_instance: AdsRequest, adTagUrl: String) {

packages/interactive_media_ads/android/src/main/kotlin/dev/flutter/packages/interactive_media_ads/InteractiveMediaAdsLibrary.g.kt

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,6 +2074,15 @@ abstract class PigeonApiContentProgressProvider(
20742074
abstract class PigeonApiAdsManager(
20752075
open val pigeonRegistrar: InteractiveMediaAdsLibraryPigeonProxyApiRegistrar
20762076
) {
2077+
/**
2078+
* List of content time offsets in seconds at which ad breaks are scheduled.
2079+
*
2080+
* The list will be empty if no ad breaks are scheduled.
2081+
*/
2082+
abstract fun adCuePoints(
2083+
pigeon_instance: com.google.ads.interactivemedia.v3.api.AdsManager
2084+
): List<Double>
2085+
20772086
/** Discards current ad break and resumes content. */
20782087
abstract fun discardAdBreak(pigeon_instance: com.google.ads.interactivemedia.v3.api.AdsManager)
20792088

@@ -2083,15 +2092,6 @@ abstract class PigeonApiAdsManager(
20832092
/** Starts playing the ads. */
20842093
abstract fun start(pigeon_instance: com.google.ads.interactivemedia.v3.api.AdsManager)
20852094

2086-
/**
2087-
* List of content time offsets in seconds at which ad breaks are scheduled.
2088-
*
2089-
* The list will be empty if no ad breaks are scheduled.
2090-
*/
2091-
abstract fun getAdCuePoints(
2092-
pigeon_instance: com.google.ads.interactivemedia.v3.api.AdsManager
2093-
): List<Double>
2094-
20952095
/** Resumes the current ad. */
20962096
abstract fun resume(pigeon_instance: com.google.ads.interactivemedia.v3.api.AdsManager)
20972097

@@ -2171,28 +2171,6 @@ abstract class PigeonApiAdsManager(
21712171
channel.setMessageHandler(null)
21722172
}
21732173
}
2174-
run {
2175-
val channel =
2176-
BasicMessageChannel<Any?>(
2177-
binaryMessenger,
2178-
"dev.flutter.pigeon.interactive_media_ads.AdsManager.getAdCuePoints",
2179-
codec)
2180-
if (api != null) {
2181-
channel.setMessageHandler { message, reply ->
2182-
val args = message as List<Any?>
2183-
val pigeon_instanceArg = args[0] as com.google.ads.interactivemedia.v3.api.AdsManager
2184-
val wrapped: List<Any?> =
2185-
try {
2186-
listOf(api.getAdCuePoints(pigeon_instanceArg))
2187-
} catch (exception: Throwable) {
2188-
InteractiveMediaAdsLibraryPigeonUtils.wrapError(exception)
2189-
}
2190-
reply.reply(wrapped)
2191-
}
2192-
} else {
2193-
channel.setMessageHandler(null)
2194-
}
2195-
}
21962174
run {
21972175
val channel =
21982176
BasicMessageChannel<Any?>(
@@ -2255,11 +2233,12 @@ abstract class PigeonApiAdsManager(
22552233
} else {
22562234
val pigeon_identifierArg =
22572235
pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg)
2236+
val adCuePointsArg = adCuePoints(pigeon_instanceArg)
22582237
val binaryMessenger = pigeonRegistrar.binaryMessenger
22592238
val codec = pigeonRegistrar.codec
22602239
val channelName = "dev.flutter.pigeon.interactive_media_ads.AdsManager.pigeon_newInstance"
22612240
val channel = BasicMessageChannel<Any?>(binaryMessenger, channelName, codec)
2262-
channel.send(listOf(pigeon_identifierArg)) {
2241+
channel.send(listOf(pigeon_identifierArg, adCuePointsArg)) {
22632242
if (it is List<*>) {
22642243
if (it.size > 1) {
22652244
callback(

packages/interactive_media_ads/android/src/test/kotlin/dev/flutter/packages/interactive_media_ads/AdsManagerProxyApiTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ class AdsManagerProxyApiTest {
4343
}
4444

4545
@Test
46-
fun getAdCuePoints() {
46+
fun adCuePoints() {
4747
val api = TestProxyApiRegistrar().getPigeonApiAdsManager()
4848

4949
val instance = mock<AdsManager>()
5050
val value = listOf(1.0)
5151
whenever(instance.adCuePoints).thenReturn(listOf(1.0f))
5252

53-
assertEquals(value, api.getAdCuePoints(instance))
53+
assertEquals(value, api.adCuePoints(instance))
5454
}
5555

5656
@Test

packages/interactive_media_ads/example/ios/RunnerTests/AdsManagerTests.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,17 @@ final class AdsManagerTests: XCTestCase {
101101

102102
XCTAssertTrue(instance.destroyCalled)
103103
}
104+
105+
func testAdCuePoints() {
106+
let registrar = TestProxyApiRegistrar()
107+
let api = registrar.apiDelegate.pigeonApiIMAAdsManager(registrar)
108+
109+
let instance = TestAdsManager.customInit()
110+
111+
let value = try? api.pigeonDelegate.adCuePoints(pigeonApi: api, pigeonInstance: instance)
112+
113+
XCTAssertEqual(value, [2.2, 3.3])
114+
}
104115
}
105116

106117
class TestAdsManager: IMAAdsManager {
@@ -146,4 +157,8 @@ class TestAdsManager: IMAAdsManager {
146157
override func destroy() {
147158
destroyCalled = true
148159
}
160+
161+
override var adCuePoints: [Any] {
162+
return [2.2, 3.3]
163+
}
149164
}

packages/interactive_media_ads/example/lib/video_ad_example_screen.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class _VideoAdExampleScreenState extends State<VideoAdExampleScreen>
7070
_adsLoader = AdsLoader(
7171
container: container,
7272
onAdsLoaded: (OnAdsLoadedData data) {
73+
debugPrint('OnAdsLoaded: (cuePoints: ${data.manager.adCuePoints})');
7374
final AdsManager manager = data.manager;
7475
_adsManager = data.manager;
7576

packages/interactive_media_ads/ios/interactive_media_ads/Sources/interactive_media_ads/AdsManagerProxyAPIDelegate.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,12 @@ class AdsManagerProxyAPIDelegate: PigeonApiDelegateIMAAdsManager {
4747
func destroy(pigeonApi: PigeonApiIMAAdsManager, pigeonInstance: IMAAdsManager) throws {
4848
pigeonInstance.destroy()
4949
}
50+
51+
func adCuePoints(pigeonApi: PigeonApiIMAAdsManager, pigeonInstance: IMAAdsManager) throws
52+
-> [Double]
53+
{
54+
return pigeonInstance.adCuePoints.map { cuePoint -> Double in
55+
return (cuePoint as! NSNumber).doubleValue
56+
}
57+
}
5058
}

packages/interactive_media_ads/ios/interactive_media_ads/Sources/interactive_media_ads/AdsRequestProxyAPIDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class AdsRequestProxyAPIDelegate: PigeonApiDelegateIMAAdsRequest {
1313
/// The current version of the `interactive_media_ads` plugin.
1414
///
1515
/// This must match the version in pubspec.yaml.
16-
static let pluginVersion = "0.2.6+7"
16+
static let pluginVersion = "0.2.7"
1717

1818
func pigeonDefaultConstructor(
1919
pigeonApi: PigeonApiIMAAdsRequest, adTagUrl: String, adDisplayContainer: IMAAdDisplayContainer,

packages/interactive_media_ads/ios/interactive_media_ads/Sources/interactive_media_ads/InteractiveMediaAdsLibrary.g.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3157,6 +3157,12 @@ final class PigeonApiIMAAdError: PigeonApiProtocolIMAAdError {
31573157
}
31583158
}
31593159
protocol PigeonApiDelegateIMAAdsManager {
3160+
/// List of content time offsets at which ad breaks are scheduled.
3161+
///
3162+
/// List of double values in seconds. Empty list for single ads or if no ad
3163+
/// breaks are scheduled.
3164+
func adCuePoints(pigeonApi: PigeonApiIMAAdsManager, pigeonInstance: IMAAdsManager) throws
3165+
-> [Double]
31603166
/// The `IMAAdsManagerDelegate` to notify with events during ad playback.
31613167
func setDelegate(
31623168
pigeonApi: PigeonApiIMAAdsManager, pigeonInstance: IMAAdsManager,
@@ -3365,13 +3371,15 @@ final class PigeonApiIMAAdsManager: PigeonApiProtocolIMAAdsManager {
33653371
} else {
33663372
let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance(
33673373
pigeonInstance as AnyObject)
3374+
let adCuePointsArg = try! pigeonDelegate.adCuePoints(
3375+
pigeonApi: self, pigeonInstance: pigeonInstance)
33683376
let binaryMessenger = pigeonRegistrar.binaryMessenger
33693377
let codec = pigeonRegistrar.codec
33703378
let channelName: String =
33713379
"dev.flutter.pigeon.interactive_media_ads.IMAAdsManager.pigeon_newInstance"
33723380
let channel = FlutterBasicMessageChannel(
33733381
name: channelName, binaryMessenger: binaryMessenger, codec: codec)
3374-
channel.sendMessage([pigeonIdentifierArg] as [Any?]) { response in
3382+
channel.sendMessage([pigeonIdentifierArg, adCuePointsArg] as [Any?]) { response in
33753383
guard let listResponse = response as? [Any?] else {
33763384
completion(.failure(createConnectionError(withChannelName: channelName)))
33773385
return

0 commit comments

Comments
 (0)