文件最后提交记录最后更新时间
[various] Update all packages to Pigeon 26 (#10450) Pigeon versions <26.0.4 aren't compatible with analyzer 8.x, which is causing conflicts for flutter/flutter, so this updates the entire repo to 26. Related: https://github.com/flutter/flutter/issues/178270 Manual fixes: - Updates camera_android_camerax and webview_flutter_android for https://github.com/flutter/packages/pull/9515 - Adds the pigeonVar_* overrides to the url_launcher_windows tests - Removes equality extensions to Pigeon data classes in in_app_purchase_storekit, as they are now generated by Pigeon, causing redeclaration errors. ## Pre-Review Checklist [^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.6 个月前
[various] Update min iOS/macOS versions (#10231) For all packages that have not already done so: - Ensure that the minimum iOS version is 13. - Ensure that the minimum macOS version is 10.15. - Ensure that the minimum Flutter SDK version in 3.35 for anything with changes from the above. In https://github.com/flutter/packages/pull/9849 I did the iOS plugins that had conditional logic for iOS <13, but I forgot to follow up with updating the minimum for the plugins that didn't have conditional logic. Because this changes min Dart SDKs, it causes autoformat changes. There are no actual code changes in this PR; all Dart file changes are purely the result of re-running dart format. This does bump the versions, even though repo policy would allow skipping version bumps for only changing min requirements, just to avoid conflating all the changes here with future releases. Part of https://github.com/flutter/flutter/issues/167735 Part of https://github.com/flutter/flutter/issues/167745 ## Pre-Review Checklist [^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.7 个月前
[various] Update all packages to Pigeon 26 (#10450) Pigeon versions <26.0.4 aren't compatible with analyzer 8.x, which is causing conflicts for flutter/flutter, so this updates the entire repo to 26. Related: https://github.com/flutter/flutter/issues/178270 Manual fixes: - Updates camera_android_camerax and webview_flutter_android for https://github.com/flutter/packages/pull/9515 - Adds the pigeonVar_* overrides to the url_launcher_windows tests - Removes equality extensions to Pigeon data classes in in_app_purchase_storekit, as they are now generated by Pigeon, causing redeclaration errors. ## Pre-Review Checklist [^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.6 个月前
[various] Update all packages to Pigeon 26 (#10450) Pigeon versions <26.0.4 aren't compatible with analyzer 8.x, which is causing conflicts for flutter/flutter, so this updates the entire repo to 26. Related: https://github.com/flutter/flutter/issues/178270 Manual fixes: - Updates camera_android_camerax and webview_flutter_android for https://github.com/flutter/packages/pull/9515 - Adds the pigeonVar_* overrides to the url_launcher_windows tests - Removes equality extensions to Pigeon data classes in in_app_purchase_storekit, as they are now generated by Pigeon, causing redeclaration errors. ## Pre-Review Checklist [^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.6 个月前
[dependabot]: Bump com.google.ads.interactivemedia.v3:interactivemedia from 3.37.0 to 3.38.0 in /packages/interactive_media_ads/android (#10262) Bumps com.google.ads.interactivemedia.v3:interactivemedia from 3.37.0 to 3.38.0. This update created a new base class, AdSlot, and moved most of the methods from CompanionAdSlot to the base class. See https://developers.google.com/interactive-media-ads/docs/sdks/android/client-side/history Also updates the minSdkVersion to 24 since Flutter 3.35 requires 24 anyways. See https://github.com/flutter/packages/pull/9851 [![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=com.google.ads.interactivemedia.v3:interactivemedia&package-manager=gradle&previous-version=3.37.0&new-version=3.38.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase. --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - @dependabot rebase will rebase this PR - @dependabot recreate will recreate this PR, overwriting any edits that have been made to it - @dependabot merge will merge this PR after your CI passes on it - @dependabot squash and merge will squash and merge this PR after your CI passes on it - @dependabot cancel merge will cancel a previously requested merge and block automerging - @dependabot reopen will reopen this PR if it is closed - @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - @dependabot show <dependency name> ignore conditions will show all of the ignore conditions of the specified dependency - @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details>7 个月前
[Many] Migrate non examples (and pigeon test) to java 17 (#10201) Fixes flutter/flutter/issues/176027 - **Update tooling to enforce java 17 compile options and kotlinOptions** - **Update interactive_media_ads and camera_android** - **Update compileOptions to java 17** - **Update changelog and pubspec for modified packages** - **Fix pigeon example** ## Pre-Review Checklist7 个月前
[interactive_media_ads] Reland "Creates and adds the interactive_media_ads plugin #6060" (#6425) Relands https://github.com/flutter/packages/pull/6060 with the addition of the multidexEnabled as mentioned in https://github.com/flutter/packages/pull/6417. See https://github.com/flutter/packages/pull/6417 for revert Part of https://github.com/flutter/flutter/issues/1342282 年前
[various] Update all packages to Pigeon 26 (#10450) Pigeon versions <26.0.4 aren't compatible with analyzer 8.x, which is causing conflicts for flutter/flutter, so this updates the entire repo to 26. Related: https://github.com/flutter/flutter/issues/178270 Manual fixes: - Updates camera_android_camerax and webview_flutter_android for https://github.com/flutter/packages/pull/9515 - Adds the pigeonVar_* overrides to the url_launcher_windows tests - Removes equality extensions to Pigeon data classes in in_app_purchase_storekit, as they are now generated by Pigeon, causing redeclaration errors. ## Pre-Review Checklist [^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.6 个月前
[various] Clean up contributing guides (#8032) Several packages had documentation about how to use Pigeon or Mockito generation; this made sense when those were rare, but they are both now extremely common in our packages. Instead, https://github.com/flutter/flutter/pull/158326 adds this information to the general documentation for contribuing to flutter/packages, so it no longer needs to be in (a random subset of) specific packages. This also removes Contributing sections from several READMEs, as READMEs should be client-focused rather than developer-focused, and puts content in CONTRIBUTING.md where needed.1 年前
Remove "All right reserved" from all files (#10066) Per guidance from legal on current preferred practice, remove "All rights reserved" from all LICENSE files and header blocks, and update the repo tool check accordingly.7 个月前
[various] Update min iOS/macOS versions (#10231) For all packages that have not already done so: - Ensure that the minimum iOS version is 13. - Ensure that the minimum macOS version is 10.15. - Ensure that the minimum Flutter SDK version in 3.35 for anything with changes from the above. In https://github.com/flutter/packages/pull/9849 I did the iOS plugins that had conditional logic for iOS <13, but I forgot to follow up with updating the minimum for the plugins that didn't have conditional logic. Because this changes min Dart SDKs, it causes autoformat changes. There are no actual code changes in this PR; all Dart file changes are purely the result of re-running dart format. This does bump the versions, even though repo policy would allow skipping version bumps for only changing min requirements, just to avoid conflating all the changes here with future releases. Part of https://github.com/flutter/flutter/issues/167735 Part of https://github.com/flutter/flutter/issues/167745 ## Pre-Review Checklist [^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.7 个月前
[various] Update all packages to Pigeon 26 (#10450) Pigeon versions <26.0.4 aren't compatible with analyzer 8.x, which is causing conflicts for flutter/flutter, so this updates the entire repo to 26. Related: https://github.com/flutter/flutter/issues/178270 Manual fixes: - Updates camera_android_camerax and webview_flutter_android for https://github.com/flutter/packages/pull/9515 - Adds the pigeonVar_* overrides to the url_launcher_windows tests - Removes equality extensions to Pigeon data classes in in_app_purchase_storekit, as they are now generated by Pigeon, causing redeclaration errors. ## Pre-Review Checklist [^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.6 个月前
README.md

interactive_media_ads

Flutter plugin for the Interactive Media Ads SDKs.

pub package

IMA SDKs make it easy to integrate multimedia ads into your websites and apps. IMA SDKs can request ads from any VAST-compliant ad server and manage ad playback in your apps. With IMA client-side SDKs, you maintain control of content video playback, while the SDK handles ad playback. Ads play in a separate video player positioned on top of the app's content video player.

Android iOS
Support SDK 21+ 13.0+

NOTE:

  • Background Audio ads and Google Dynamic Ad Insertion methods are currently not supported.

IMA client-side overview

Implementing IMA client-side involves five main SDK components, which are demonstrated in this guide:

  • AdDisplayContainer: A container object where ads are rendered.
  • AdsLoader: Requests ads and handles events from ads request responses. You should only instantiate one ads loader, which can be reused throughout the life of the application.
  • AdsRequest: An object that defines an ads request. Ads requests specify the URL for the VAST ad tag, as well as additional parameters, such as ad dimensions.
  • AdsManager: Contains the response to the ads request, controls ad playback, and listens for ad events fired by the SDK.
  • AdsManagerDelegate: Handles ad events and errors that occur during ad or stream initialization and playback.

Usage

This guide demonstrates how to integrate the IMA SDK into a new Widget using the video_player plugin to display content.

1. Update Android App

If not building for Android, skip this step.

Update Android Manifest

Add the user permissions required by the IMA SDK for requesting ads in android/app/src/main/AndroidManifest.xml.

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Required permissions for the IMA SDK -->
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

Update Android App-level Gradle

The IMA SDK requires library desugaring enabled, which you must do by setting coreLibraryDesugaringEnabled true and adding coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.5' as a dependency in the android/app/build.gradle file. For more details, see Java 11+ APIs available through desugaring with the nio specification.

android {
// ···
    compileOptions {
        coreLibraryDesugaringEnabled true
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
    // ···
}
// ···
dependencies {
    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.5'
    // ···
}

2. Add Imports

Add the import statements for the interactive_media_ads and video_player. Both plugins should already be added to your pubspec.yaml.

import 'package:interactive_media_ads/interactive_media_ads.dart';
import 'package:video_player/video_player.dart';

3. Create a New Widget

Create a new StatefulWidget that handles displaying Ads and playing content.

/// Example widget displaying an Ad before a video.
class AdExampleWidget extends StatefulWidget {
  /// Constructs an [AdExampleWidget].
  const AdExampleWidget({super.key});

  @override
  State<AdExampleWidget> createState() => _AdExampleWidgetState();
}

class _AdExampleWidgetState extends State<AdExampleWidget>
    with WidgetsBindingObserver {
  // IMA sample tag for a pre-, mid-, and post-roll, single inline video ad. See more IMA sample
  // tags at https://developers.google.com/interactive-media-ads/docs/sdks/html5/client-side/tags
  static const String _adTagUrl =
      'https://pubads.g.doubleclick.net/gampad/ads?iu=/21775744923/external/vmap_ad_samples&sz=640x480&cust_params=sample_ar%3Dpremidpost&ciu_szs=300x250&gdfp_req=1&ad_rule=1&output=vmap&unviewed_position_start=1&env=vp&impl=s&cmsid=496&vid=short_onecue&correlator=';

  // The AdsLoader instance exposes the request ads method.
  late final AdsLoader _adsLoader;

  // AdsManager exposes methods to control ad playback and listen to ad events.
  AdsManager? _adsManager;

  // ···
  // Whether the widget should be displaying the content video. The content
  // player is hidden while Ads are playing.
  bool _shouldShowContentVideo = false;

  // Controls the content video player.
  late final VideoPlayerController _contentVideoController;

  // Periodically updates the SDK of the current playback progress of the
  // content video.
  Timer? _contentProgressTimer;

  // Provides the SDK with the current playback progress of the content video.
  // This is required to support mid-roll ads.
  final ContentProgressProvider _contentProgressProvider =
      ContentProgressProvider();
  // ···
  @override
  Widget build(BuildContext context) {
    // ···
  }

}

4. Add the Video Players

Instantiate the AdDisplayContainer for playing Ads and the VideoPlayerController for playing content.

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(settings: AdsRenderingSettings(enablePreloading: true));
      },
      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);
  },
);

@override
void initState() {
  super.initState();
  // ···
  _contentVideoController =
      VideoPlayerController.networkUrl(
          Uri.parse(
            'https://storage.googleapis.com/gvabox/media/samples/stock.mp4',
          ),
        )
        ..addListener(() {
          if (_contentVideoController.value.isCompleted) {
            _adsLoader.contentComplete();
          }
          setState(() {});
        })
        ..initialize().then((_) {
          // Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
          setState(() {});
        });
}

5. Implement the build Method

Return a Widget that contains the ad player and the content player.

@override
Widget build(BuildContext context) {
  return Scaffold(
    body: Center(
      child: SizedBox(
        width: 300,
        child: !_contentVideoController.value.isInitialized
            ? Container()
            : AspectRatio(
                aspectRatio: _contentVideoController.value.aspectRatio,
                child: Stack(
                  children: <Widget>[
                    // The display container must be on screen before any Ads can be
                    // loaded and can't be removed between ads. This handles clicks for
                    // ads.
                    _adDisplayContainer,
                    if (_shouldShowContentVideo)
                      VideoPlayer(_contentVideoController),
                  ],
                ),
              ),
      ),
    ),
    floatingActionButton:
        _contentVideoController.value.isInitialized && _shouldShowContentVideo
        ? FloatingActionButton(
            onPressed: () {
              setState(() {
                _contentVideoController.value.isPlaying
                    ? _contentVideoController.pause()
                    : _contentVideoController.play();
              });
            },
            child: Icon(
              _contentVideoController.value.isPlaying
                  ? Icons.pause
                  : Icons.play_arrow,
            ),
          )
        : null,
  );
}

6. Request Ads

Handle requesting ads and add event listeners to handle when content should be displayed or hidden.

Future<void> _requestAds(AdDisplayContainer container) {
  return _adsLoader.requestAds(
    AdsRequest(
      adTagUrl: _adTagUrl,
      contentProgressProvider: _contentProgressProvider,
    ),
  );
}

Future<void> _resumeContent() async {
  setState(() {
    _shouldShowContentVideo = true;
  });

  if (_adsManager != null) {
    _contentProgressTimer = Timer.periodic(
      const Duration(milliseconds: 200),
      (Timer timer) async {
        if (_contentVideoController.value.isInitialized) {
          final Duration? progress = await _contentVideoController.position;
          if (progress != null) {
            await _contentProgressProvider.setProgress(
              progress: progress,
              duration: _contentVideoController.value.duration,
            );
          }
        }
      },
    );
  }

  await _contentVideoController.play();
}

Future<void> _pauseContent() {
  setState(() {
    _shouldShowContentVideo = false;
  });
  _contentProgressTimer?.cancel();
  _contentProgressTimer = null;
  return _contentVideoController.pause();
}

7. Dispose Resources

Dispose the content player and destroy the AdsManager.

@override
void dispose() {
  super.dispose();
  _contentProgressTimer?.cancel();
  _contentVideoController.dispose();
  _adsManager?.destroy();
  // ···
}

That's it! You're now requesting and displaying ads with the IMA SDK. To learn about additional SDK features, see the API reference.

Contributing

For information on contributing to this plugin, see CONTRIBUTING.md.