创建全屏视频广告,,APP启动后在第一个页面调用onLoad中的代码
onLoad(){
if(window.plus != undefined){
// console.log('5+APP打开,走这里')
let _this = this;
var adFull = null;
function fullVideoAd() {
if (adFull) {
console.log('正在加载全屏视频广告');
return;
}
console.log('#全屏视频广告#');
adFull = plus.ad.createFullScreenVideoAd({
adpid: '1507000611'
}); //1507000611是HBuilder测试基座使用的广告位,正式环境下请使用在uni-AD后台申请的
adFull.onLoad(function() {
console.log('加载成功')
adFull.show();
});
adFull.onError(function(e) {
console.log('加载失败: ' + JSON.stringify(e));
adFull.destroy();
adFull = null;
_this.$goBack(4,'/pages/video/index')
});
adFull.onClose(function(e) {
if (e.isEnded) {
console.log('全屏视频播放完成');
plus.nativeUI.toast('全屏视频播放完成');
_this.$goBack(4,'/pages/video/index')
//这里实现完成全屏视频逻辑
} else {
console.log('全屏视频未播放完成关闭!')
_this.$goBack(4,'/pages/video/index')
}
adFull.destroy();
adFull = null;
});
adFull.load();
}
fullVideoAd()
}else{
this.$goBack(4,'/pages/video/index')
}
}
效果图如下:
创建:插屏广告
onLoad(){
var adInter = null;
//插屏广告
function fullVideoAd() {
if (adInter) {
console.log('正在加载插屏广告');
return;
}
console.log('#插屏广告#');
adInter = plus.ad.createInterstitialAd({
adpid: '1111111113'
}); //1111111113是HBuilder测试基座使用的广告位,正式环境下请使用在uni-AD后台申请的广告位
adInter.onLoad(function() {
console.log('加载成功')
adInter.show();
});
adInter.onError(function(e) {
console.log('加载失败: ' + JSON.stringify(e));
adInter.destroy();
adInter = null;
});
adInter.onClose(function(e) {
console.log('插屏广告被关闭');
adInter.destroy();
adInter = null;
});
adInter.load();
}
fullVideoAd();
}
效果如下图,插屏广告
创建:激励视频广告
//激励视频广告
onLoad() {
//激励视频广告
if(window.plus != undefined){
// console.log('5+APP打开,走这里')
let _this = this;
var adReward = null;
function rewardedVideoAd() {
if (adReward) {
console.log('正在加载激励视频广告');
return;
}
console.log('#视频激励广告#');
adReward = plus.ad.createRewardedVideoAd({
adpid: '1507000689'
});
adReward.onLoad(function() {
console.log('加载成功')
adReward.show();
});
adReward.onError(function(e) {
console.log('加载失败: ' + JSON.stringify(e));
adReward.destroy();
adReward = null;
});
adReward.onClose(function(e) {
if (e.isEnded) {
console.log('激励视频播放完成');
plus.nativeUI.toast('激励视频播放完成');
//这里实现完成激励视频逻辑
_this.$goBack(4,'/pages/video/index')
} else {
console.log('激励视频未播放完成关闭!')
_this.$goBack(4,'/pages/video/index')
}
adReward.destroy();
adReward = null;
});
adReward.load();
}
rewardedVideoAd()
}else{
// console.log('网页中打开页面走这里')
this.$goBack(4,'/pages/video/index')
}
},
效果如下图,全屏的视频广告,window.plus != undefined判断是否可以调用plus方法