Closed tudosxxx closed 11 months ago
Hi @hx269988653, Thanks for filing the issue, Please provide a minimal reproducible code sample, This helps to better investigate the issue.
Thank you.
import 'package:cached_video_player/cached_video_player.dart';
import 'package:flutter/material.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';
// cached_video_player: ^2.0.0-dev.1
// google_mobile_ads: ^0.13.3
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
VideoPlayerController? controller;
BannerAd? anchoredBanner;
@override
void initState() {
super.initState();
controller = VideoPlayerController.network(
'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4')
..initialize().then((_) {
controller!.setLooping(true);
controller!.play();
setState(() {
});
});
}
Future<void> createAnchoredBanner() async {
final AnchoredAdaptiveBannerAdSize? size =
await AdSize.getAnchoredAdaptiveBannerAdSize(
Orientation.portrait,
MediaQuery.of(context).size.width.truncate(),
);
if (size == null) {
print('Unable to get height of anchored banner.');
return;
}
final BannerAd banner = BannerAd(
size: size,
request: AdRequest(),
adUnitId: 'ca-app-pub-3940256099942544/6300978111',
listener: BannerAdListener(
onAdLoaded: (Ad ad) {
print('$BannerAd loaded.');
anchoredBanner = ad as BannerAd?;
setState(() {});
},
onAdFailedToLoad: (Ad ad, LoadAdError error) {
print('$BannerAd failedToLoad: $error');
ad.dispose();
},
onAdOpened: (Ad ad) => print('$BannerAd onAdOpened.'),
onAdClosed: (Ad ad) => print('$BannerAd onAdClosed.'),
),
);
return banner.load();
}
@override
Widget build(BuildContext context) {
if(anchoredBanner == null)
createAnchoredBanner();
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Stack(
children: [
Center(
child: controller == null
? Text('Loading...')
: AspectRatio(
aspectRatio: controller!.value.aspectRatio,
//_controller.value.aspectRatio,
child: VideoPlayer(controller!),
),
),
Align(
alignment: Alignment.bottomCenter,
child: anchoredBanner == null
? Container()
: Container(
color: Colors.black54,
width: anchoredBanner!.size.width.toDouble(),
height: anchoredBanner!.size.height.toDouble(),
child: AdWidget(ad: anchoredBanner!),
))
],
));
}
@override
void dispose() {
controller!.dispose();
super.dispose();
}
}
@tudosxxx It looks like you are using the official video_player
plugin and not cached_video_player:
I tried your code sample using the latest video_player: ^2.1.14
plugin I was able to reproduce the issue on the latest stable and the master channel. The issue is reproducible only on Android and works fine on IOS
Problem stil exists: google_mobile_ads: ^2.0.0 video_player: ^2.2.3
Hi @MarcinWad,
Try updating to the latest version of the google_mobile_ads plugin (3.0.0
) and see if that resolves your issue. If not please let us know.
Closing due to inactivity. Please follow-up if the issue persists using version 3.0.0
google_mobile_ads: ^0.13.3
When the advertisement is loaded on the video page, the sound of the video will appear, and the video picture will be static. This will happen if there is an AdWidget on the video page。
Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, 2.2.2, on Microsoft Windows [Version 10.0.18363.1734]) [√] Android toolchain - develop for Android devices (Android SDK version 30.0.2) [√] Chrome - develop for the web [X] Visual Studio - develop for Windows X Visual Studio not installed; this is necessary for Windows development. Download at https://visualstudio.microsoft.com/downloads/. Please install the "Desktop development with C++" workload, including all of its default components [!] Android Studio (not installed) [√] Connected device (4 available)
! Doctor found issues in 2 categories.