forked from flutter/flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[interactive_media_ads] Adds support for mid-roll ads (flutter#7407)
Adds `ContentProgressProvider` and adds `AdsRequest.contentProgressProvider` field. This changes the platform interface `AdsRequest` to `PlatformAdsRequest`, so the `PlatformContentProgressProvider` can be passed to it. And the app-facing `AdsRequest` can take a `ContentProgressProver`. Fixes flutter#154261
- Loading branch information
1 parent
4f2b9cd
commit c7406b3
Showing
37 changed files
with
910 additions
and
44 deletions.
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_interface.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
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.