-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[interactive_media_ads] Adds support for mid-roll ads #7407
Merged
Merged
Changes from 29 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
905cd48
interface and app-facing implementation for content progress provider
bparrishMines 89e4434
partial android implementation
bparrishMines 427ded9
pass progress and duration to set progress
bparrishMines e8fd08d
android implementation mostly
bparrishMines 55e080b
separate adsrequest into its own app-facing class
bparrishMines 76efd5a
finish android impl and add to example app
bparrishMines 83ac065
working mid rolls
bparrishMines 837e345
fix test names
bparrishMines fb2baee
android tests
bparrishMines cef317c
change to swift gen
bparrishMines 213f2da
ios impl
bparrishMines 209c544
android class
bparrishMines ce5a8be
version bump
bparrishMines 8d61008
comment pigeon android again
bparrishMines 0e5e86c
Merge branch 'main' of github.com:flutter/packages into ima_contentpp
bparrishMines bc9c047
add the suppress
bparrishMines 3c56859
comment out content duration
bparrishMines e5d1ba6
Merge branch 'main' of github.com:flutter/packages into ima_midrolls
bparrishMines 90181e6
regen and format
bparrishMines a799357
fix version bump
bparrishMines 86ddf15
Merge branch 'ima_contentpp' into ima_midrolls
bparrishMines 4f2e9ff
update geng
bparrishMines 9e883fe
update pr to other pr
bparrishMines f1e6897
try to test requestads
bparrishMines 8804a14
Merge branch 'main' of github.com:flutter/packages into ima_midrolls
bparrishMines a5d73a8
version bump
bparrishMines e458f49
readme update
bparrishMines 5fb899b
update i think
bparrishMines a702ffd
Merge branch 'main' of github.com:flutter/packages into ima_midrolls
bparrishMines c80ef68
improve imports
bparrishMines d183264
update interval
bparrishMines 2319286
Merge branch 'main' of github.com:flutter/packages into ima_midrolls
bparrishMines File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'content_progress_provider.dart'; | ||
import 'platform_interface/platform_ads_request.dart'; | ||
|
||
/// An object containing the data used to request ads from the server. | ||
class AdsRequest { | ||
/// Creates an [AdsRequest]. | ||
AdsRequest({ | ||
required String adTagUrl, | ||
ContentProgressProvider? contentProgressProvider, | ||
}) : this.fromPlatform( | ||
PlatformAdsRequest( | ||
adTagUrl: adTagUrl, | ||
contentProgressProvider: contentProgressProvider?.platform, | ||
), | ||
); | ||
|
||
/// Constructs an [AdsRequest] from a specific platform implementation. | ||
AdsRequest.fromPlatform(this.platform); | ||
|
||
/// Implementation of [PlatformAdsRequest] for the current platform. | ||
final PlatformAdsRequest platform; | ||
|
||
/// The URL from which ads will be requested. | ||
String get adTagUrl => platform.adTagUrl; | ||
|
||
/// A [ContentProgressProvider] instance to allow scheduling of ad breaks | ||
/// based on content progress (cue points). | ||
ContentProgressProvider? get contentProgressProvider => platform | ||
.contentProgressProvider != | ||
null | ||
? ContentProgressProvider.fromPlatform(platform.contentProgressProvider!) | ||
: null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import 'package:flutter/widgets.dart'; | |
import '../platform_interface/platform_interface.dart'; | ||
import 'android_ad_display_container.dart'; | ||
import 'android_ads_manager.dart'; | ||
import 'android_content_progress_provider.dart'; | ||
import 'enum_converter_utils.dart'; | ||
import 'interactive_media_ads.g.dart' as ima; | ||
import 'interactive_media_ads_proxy.dart'; | ||
|
@@ -79,13 +80,18 @@ base class AndroidAdsLoader extends PlatformAdsLoader { | |
} | ||
|
||
@override | ||
Future<void> requestAds(AdsRequest request) async { | ||
Future<void> requestAds(PlatformAdsRequest request) async { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The platform implementations haven't been exposed yet, so this shouldn't be a breaking change. |
||
final ima.AdsLoader adsLoader = await _adsLoaderFuture; | ||
|
||
final ima.AdsRequest androidRequest = await _sdkFactory.createAdsRequest(); | ||
|
||
await Future.wait(<Future<void>>[ | ||
androidRequest.setAdTagUrl(request.adTagUrl), | ||
if (request.contentProgressProvider != null) | ||
androidRequest.setContentProgressProvider( | ||
(request.contentProgressProvider! as AndroidContentProgressProvider) | ||
.progressProvider, | ||
), | ||
adsLoader.requestAds(androidRequest), | ||
]); | ||
} | ||
|
70 changes: 70 additions & 0 deletions
70
packages/interactive_media_ads/lib/src/android/android_content_progress_provider.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:meta/meta.dart'; | ||
|
||
import '../platform_interface/platform_content_progress_provider.dart'; | ||
import 'interactive_media_ads.g.dart' as ima; | ||
import 'interactive_media_ads_proxy.dart'; | ||
|
||
/// Android implementation of [PlatformContentProgressProviderCreationParams]. | ||
final class AndroidContentProgressProviderCreationParams | ||
extends PlatformContentProgressProviderCreationParams { | ||
/// Constructs a [AndroidContentProgressProviderCreationParams]. | ||
const AndroidContentProgressProviderCreationParams({ | ||
@visibleForTesting InteractiveMediaAdsProxy? proxy, | ||
}) : _proxy = proxy ?? const InteractiveMediaAdsProxy(), | ||
super(); | ||
|
||
/// Creates a [AndroidContentProgressProviderCreationParams] from an instance of | ||
/// [PlatformContentProgressProviderCreationParams]. | ||
factory AndroidContentProgressProviderCreationParams.fromPlatformContentProgressProviderCreationParams( | ||
// Placeholder to prevent requiring a breaking change if params are added to | ||
// PlatformContentProgressProviderCreationParams. | ||
// ignore: avoid_unused_constructor_parameters | ||
PlatformContentProgressProviderCreationParams params, { | ||
@visibleForTesting InteractiveMediaAdsProxy? proxy, | ||
}) { | ||
return AndroidContentProgressProviderCreationParams(proxy: proxy); | ||
} | ||
|
||
final InteractiveMediaAdsProxy _proxy; | ||
} | ||
|
||
/// Android implementation of [PlatformContentProgressProvider]. | ||
base class AndroidContentProgressProvider | ||
extends PlatformContentProgressProvider { | ||
/// Constructs an [AndroidContentProgressProvider]. | ||
AndroidContentProgressProvider(super.params) : super.implementation(); | ||
|
||
/// The native Android ContentProgressProvider. | ||
/// | ||
/// This allows the SDK to track progress of the content video. | ||
@internal | ||
late final ima.ContentProgressProvider progressProvider = | ||
_androidParams._proxy.newContentProgressProvider(); | ||
|
||
late final AndroidContentProgressProviderCreationParams _androidParams = | ||
params is AndroidContentProgressProviderCreationParams | ||
? params as AndroidContentProgressProviderCreationParams | ||
: AndroidContentProgressProviderCreationParams | ||
.fromPlatformContentProgressProviderCreationParams( | ||
params, | ||
); | ||
|
||
@override | ||
Future<void> setProgress({ | ||
required Duration progress, | ||
required Duration duration, | ||
}) async { | ||
return progressProvider.setContentProgress( | ||
_androidParams._proxy.newVideoProgressUpdate( | ||
currentTimeMs: progress.inMilliseconds, | ||
durationMs: duration.inMilliseconds, | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@harold1208 @stuartmorgan What are your thoughts on the interval to be used here in the example? This works for me on Android and iOS, but this is a Flutter specific workaround to handle the SDK running on a separate thread.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For context, this timer updates the SDK of the progress of the content video with this being the interval between updates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per our offline discussion with the IMA team, a 200ms interval would be the ideal value.