为Flutter应用植入视频广告的最佳方式是什么?



正在制作视频存储和流媒体应用程序。现在我正在尝试添加广告到应用程序。推广应用视频广告的最佳方式是什么?我知道有一个google_mobile_ads包,但是由于AdMob的规定,我不能连续显示多个视频广告。我想做一些类似于YouTube的事情,向用户展示一系列2个广告(在我的情况下,每30分钟的内容一个广告)。

你能做的是,当视频开始时,获得视频总时长,并确定你想要展示广告的频率。然后使用侦听器跟踪当前位置并不时显示广告。我做了这样的事情:

int adEvery = 0;
List<int> adIntervalSeconds = []; //timestamps at which ad will be shown
bool throttle = false;
videoPlayerController.addListener(() {
int durationInSec = chewieController!.videoPlayerController.value.duration.inSeconds;
int positionInSec = chewieController!.videoPlayerController.value.position.inSeconds;
//1500 sec = 25 minutes, isDurationLoaded bool used to make sure it run just once.
if (durationInSec > 1500 && isDurationLoaded == false) {
isDurationLoaded = true;
//if duration > 25 mins then show ad every 20 mins approx.
totalAds = (durationInSec ~/ 1200).toInt();
adEvery = (durationInSec ~/ totalAds).toInt();
//get timestamps in seconds list at which ad should be shown
for (int i = 1; i < totalAds; i++) {
adIntervalSeconds.add(adEvery * i);
}     

}
if (videoPlayerController.value.isPlaying &&
adIntervalSeconds.isNotEmpty &&
adIntervalSeconds.contains(positionInSec) &&
throttle == false) {
throttle = true;

Future.delayed(const Duration(seconds: 2), () {
throttle = false;
});
adIntervalSeconds.remove(positionInSec);
showInterstitial();
}
} 

这就是我想出来的。

最新更新