diff --git a/packages/interactive_media_ads/CHANGELOG.md b/packages/interactive_media_ads/CHANGELOG.md index ebf0512682ac7..de312403dfb04 100644 --- a/packages/interactive_media_ads/CHANGELOG.md +++ b/packages/interactive_media_ads/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.2.2+5 + +* Changes the example app to initialize the `AdsLoader` in `onContainerAdded`. + ## 0.2.2+4 * Adds internal wrapper for Android native `AdProgressInfo`. diff --git a/packages/interactive_media_ads/README.md b/packages/interactive_media_ads/README.md index 74441a71def5f..d3e1817f09bae 100644 --- a/packages/interactive_media_ads/README.md +++ b/packages/interactive_media_ads/README.md @@ -14,8 +14,6 @@ a separate video player positioned on top of the app's content video player. | **Support** | SDK 21+ | 12.0+ | **NOTE:** -* The initial release for this package supports linear pre-roll video ads on iOS and Android - platforms. * Companion ads, Background Audio ads and Google Dynamic Ad Insertion methods are currently not supported. @@ -95,7 +93,7 @@ class _AdExampleWidgetState extends State // ยทยทยท // Whether the widget should be displaying the content video. The content // player is hidden while Ads are playing. - bool _shouldShowContentVideo = true; + bool _shouldShowContentVideo = false; // Controls the content video player. late final VideoPlayerController _contentVideoController; @@ -126,6 +124,44 @@ for playing content. ```dart late final AdDisplayContainer _adDisplayContainer = AdDisplayContainer( onContainerAdded: (AdDisplayContainer container) { + _adsLoader = AdsLoader( + container: container, + onAdsLoaded: (OnAdsLoadedData data) { + final AdsManager manager = data.manager; + _adsManager = data.manager; + + manager.setAdsManagerDelegate(AdsManagerDelegate( + onAdEvent: (AdEvent event) { + debugPrint('OnAdEvent: ${event.type} => ${event.adData}'); + switch (event.type) { + case AdEventType.loaded: + manager.start(); + case AdEventType.contentPauseRequested: + _pauseContent(); + case AdEventType.contentResumeRequested: + _resumeContent(); + case AdEventType.allAdsCompleted: + manager.destroy(); + _adsManager = null; + case AdEventType.clicked: + case AdEventType.complete: + case _: + } + }, + onAdErrorEvent: (AdErrorEvent event) { + debugPrint('AdErrorEvent: ${event.error.message}'); + _resumeContent(); + }, + )); + + manager.init(); + }, + onAdsLoadError: (AdsLoadErrorData data) { + debugPrint('OnAdsLoadError: ${data.error.message}'); + _resumeContent(); + }, + ); + // Ads can't be requested until the `AdDisplayContainer` has been added to // the native View hierarchy. _requestAds(container); @@ -211,44 +247,6 @@ Handle requesting ads and add event listeners to handle when content should be d ```dart Future _requestAds(AdDisplayContainer container) { - _adsLoader = AdsLoader( - container: container, - onAdsLoaded: (OnAdsLoadedData data) { - final AdsManager manager = data.manager; - _adsManager = data.manager; - - manager.setAdsManagerDelegate(AdsManagerDelegate( - onAdEvent: (AdEvent event) { - debugPrint('OnAdEvent: ${event.type} => ${event.adData}'); - switch (event.type) { - case AdEventType.loaded: - manager.start(); - case AdEventType.contentPauseRequested: - _pauseContent(); - case AdEventType.contentResumeRequested: - _resumeContent(); - case AdEventType.allAdsCompleted: - manager.destroy(); - _adsManager = null; - case AdEventType.clicked: - case AdEventType.complete: - case _: - } - }, - onAdErrorEvent: (AdErrorEvent event) { - debugPrint('AdErrorEvent: ${event.error.message}'); - _resumeContent(); - }, - )); - - manager.init(); - }, - onAdsLoadError: (AdsLoadErrorData data) { - debugPrint('OnAdsLoadError: ${data.error.message}'); - _resumeContent(); - }, - ); - return _adsLoader.requestAds(AdsRequest( adTagUrl: _adTagUrl, contentProgressProvider: _contentProgressProvider, diff --git a/packages/interactive_media_ads/android/src/main/kotlin/dev/flutter/packages/interactive_media_ads/AdsRequestProxyApi.kt b/packages/interactive_media_ads/android/src/main/kotlin/dev/flutter/packages/interactive_media_ads/AdsRequestProxyApi.kt index 08333ec3d9898..8731c0ce4b527 100644 --- a/packages/interactive_media_ads/android/src/main/kotlin/dev/flutter/packages/interactive_media_ads/AdsRequestProxyApi.kt +++ b/packages/interactive_media_ads/android/src/main/kotlin/dev/flutter/packages/interactive_media_ads/AdsRequestProxyApi.kt @@ -21,7 +21,7 @@ class AdsRequestProxyApi(override val pigeonRegistrar: ProxyApiRegistrar) : * * This must match the version in pubspec.yaml. */ - const val pluginVersion = "0.2.2+4" + const val pluginVersion = "0.2.2+5" } override fun setAdTagUrl(pigeon_instance: AdsRequest, adTagUrl: String) { diff --git a/packages/interactive_media_ads/example/lib/main.dart b/packages/interactive_media_ads/example/lib/main.dart index 9bafdda819e9f..01cdb603dc012 100644 --- a/packages/interactive_media_ads/example/lib/main.dart +++ b/packages/interactive_media_ads/example/lib/main.dart @@ -52,7 +52,7 @@ class _AdExampleWidgetState extends State // #docregion example_widget // Whether the widget should be displaying the content video. The content // player is hidden while Ads are playing. - bool _shouldShowContentVideo = true; + bool _shouldShowContentVideo = false; // Controls the content video player. late final VideoPlayerController _contentVideoController; @@ -70,6 +70,44 @@ class _AdExampleWidgetState extends State // #docregion ad_and_content_players late final AdDisplayContainer _adDisplayContainer = AdDisplayContainer( onContainerAdded: (AdDisplayContainer container) { + _adsLoader = AdsLoader( + container: container, + onAdsLoaded: (OnAdsLoadedData data) { + final AdsManager manager = data.manager; + _adsManager = data.manager; + + manager.setAdsManagerDelegate(AdsManagerDelegate( + onAdEvent: (AdEvent event) { + debugPrint('OnAdEvent: ${event.type} => ${event.adData}'); + switch (event.type) { + case AdEventType.loaded: + manager.start(); + case AdEventType.contentPauseRequested: + _pauseContent(); + case AdEventType.contentResumeRequested: + _resumeContent(); + case AdEventType.allAdsCompleted: + manager.destroy(); + _adsManager = null; + case AdEventType.clicked: + case AdEventType.complete: + case _: + } + }, + onAdErrorEvent: (AdErrorEvent event) { + debugPrint('AdErrorEvent: ${event.error.message}'); + _resumeContent(); + }, + )); + + manager.init(); + }, + onAdsLoadError: (AdsLoadErrorData data) { + debugPrint('OnAdsLoadError: ${data.error.message}'); + _resumeContent(); + }, + ); + // Ads can't be requested until the `AdDisplayContainer` has been added to // the native View hierarchy. _requestAds(container); @@ -127,44 +165,6 @@ class _AdExampleWidgetState extends State // #docregion request_ads Future _requestAds(AdDisplayContainer container) { - _adsLoader = AdsLoader( - container: container, - onAdsLoaded: (OnAdsLoadedData data) { - final AdsManager manager = data.manager; - _adsManager = data.manager; - - manager.setAdsManagerDelegate(AdsManagerDelegate( - onAdEvent: (AdEvent event) { - debugPrint('OnAdEvent: ${event.type} => ${event.adData}'); - switch (event.type) { - case AdEventType.loaded: - manager.start(); - case AdEventType.contentPauseRequested: - _pauseContent(); - case AdEventType.contentResumeRequested: - _resumeContent(); - case AdEventType.allAdsCompleted: - manager.destroy(); - _adsManager = null; - case AdEventType.clicked: - case AdEventType.complete: - case _: - } - }, - onAdErrorEvent: (AdErrorEvent event) { - debugPrint('AdErrorEvent: ${event.error.message}'); - _resumeContent(); - }, - )); - - manager.init(); - }, - onAdsLoadError: (AdsLoadErrorData data) { - debugPrint('OnAdsLoadError: ${data.error.message}'); - _resumeContent(); - }, - ); - return _adsLoader.requestAds(AdsRequest( adTagUrl: _adTagUrl, contentProgressProvider: _contentProgressProvider, diff --git a/packages/interactive_media_ads/ios/interactive_media_ads/Sources/interactive_media_ads/AdsRequestProxyAPIDelegate.swift b/packages/interactive_media_ads/ios/interactive_media_ads/Sources/interactive_media_ads/AdsRequestProxyAPIDelegate.swift index 9e3efc5a5e32b..4807a8343598d 100644 --- a/packages/interactive_media_ads/ios/interactive_media_ads/Sources/interactive_media_ads/AdsRequestProxyAPIDelegate.swift +++ b/packages/interactive_media_ads/ios/interactive_media_ads/Sources/interactive_media_ads/AdsRequestProxyAPIDelegate.swift @@ -13,7 +13,7 @@ class AdsRequestProxyAPIDelegate: PigeonApiDelegateIMAAdsRequest { /// The current version of the `interactive_media_ads` plugin. /// /// This must match the version in pubspec.yaml. - static let pluginVersion = "0.2.2+4" + static let pluginVersion = "0.2.2+5" func pigeonDefaultConstructor( pigeonApi: PigeonApiIMAAdsRequest, adTagUrl: String, adDisplayContainer: IMAAdDisplayContainer, diff --git a/packages/interactive_media_ads/pubspec.yaml b/packages/interactive_media_ads/pubspec.yaml index 0fc37ddec8975..8cdac5d3c9152 100644 --- a/packages/interactive_media_ads/pubspec.yaml +++ b/packages/interactive_media_ads/pubspec.yaml @@ -2,7 +2,7 @@ name: interactive_media_ads description: A Flutter plugin for using the Interactive Media Ads SDKs on Android and iOS. repository: https://github.com/flutter/packages/tree/main/packages/interactive_media_ads issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+interactive_media_ads%22 -version: 0.2.2+4 # This must match the version in +version: 0.2.2+5 # This must match the version in # `android/src/main/kotlin/dev/flutter/packages/interactive_media_ads/AdsRequestProxyApi.kt` and # `ios/interactive_media_ads/Sources/interactive_media_ads/AdsRequestProxyAPIDelegate.swift`