激励广告组件多次加载,后面一次只有声音没有画面?
页面A跳转页面B,期间需要看一个广告。接入后能够正常显示第一个广告 播放完成后点击关闭能够正常跳转页面B 但是出现了第二个广告的声音。
测试下来还发现 如果点击第一个广告的关闭慢点 好像就不会触发第二个广告的声音,如果广告结束马上点击就必定触发第二个广告的声音。
仅为微信开发者工具的测试结果 手机端测试固定给我加载一个小游戏 不是视频广告 无法复现。
function createAdInstance() {
if (taro.Taro.getEnv() === "WEAPP" && !videoAd) {
try {
const ad = taro.Taro.createRewardedVideoAd({
adUnitId: "adunit-74e3daa78385ae2c"
});
ad.onLoad((res) => {
console.log("激励视频广告加载", res);
});
ad.onError((err) => {
console.error("激励视频广告加载失败", err);
});
ad.onClose((res) => {
console.log("激励视频广告关闭", res);
if (res && res.isEnded) {
ad.offClose((closeRes) => {
console.log("激励视频广告关闭", closeRes);
});
ad.offError((err) => {
console.error("激励视频广告加载失败", err);
});
ad.offLoad((loadRes) => {
console.log("激励视频广告加载", loadRes);
});
QueryLimitManager.incrementQueryCount();
taro.Taro.navigateTo({ url: "/pages/report/index" });
} else {
taro.Taro.showToast({
title: "需要完整观看视频哦",
icon: "none"
});
}
});
setVideoAd(ad);
} catch (err) {
console.error("创建广告实例失败", err);
}
}
}
taro.taroExports.useLoad(() => {
console.log("useLoad 页面加载");
createAdInstance();
console.log("videoAd:", videoAd);
});
taro.taroExports.useDidShow(() => {
console.log("useShow 页面显示");
console.log("videoAd:", videoAd);
});
taro.taroExports.useDidHide(() => {
console.log("useDidHide 页面隐藏");
console.log("videoAd:", videoAd);
});
function handleQuery() {
return __async(this, null, function* () {
if (!validatePhone(phone) && !validateLandLine(phone)) {
taro.Taro.showToast({ title: "请输入有效手机号", icon: "none" });
return;
}
dispatch(common.setPhoneNumber(phone));
try {
taro.Taro.showLoading({ title: "查询中...", mask: true });
dispatch(common.fetchPhoneMarks(phone));
taro.Taro.hideLoading();
} catch (error) {
taro.Taro.hideLoading();
taro.Taro.showToast({
title: "查询失败,请重试",
icon: "none"
});
return;
}
if (QueryLimitManager.checkShouldShowAd()) {
const { confirm } = yield taro.Taro.showModal({
title: "提示",
content: "免费次数已用完,需要观看一个广告才能继续查询哦",
confirmText: "立即观看",
cancelText: "暂不观看"
});
if (!confirm)
return;
if (!videoAd) {
taro.Taro.showToast({ title: "广告加载失败,请重试", icon: "none" });
return;
}
try {
console.log("videoAd:", videoAd);
return yield videoAd.show().then(() => {
console.log("显示广告成功");
}).catch(() => {
console.log("失败重试");
videoAd.load().then(() => videoAd.show()).catch((err) => {
console.error("激励视频 广告显示失败", err);
});
});
} catch (err) {
console.error("广告展示失败:", err);
taro.Taro.showToast({ title: "广告加载失败,请重试", icon: "none" });
return;
}
} else {
console.log("不需要显示广告");
QueryLimitManager.incrementQueryCount();
taro.Taro.showToast({
title: `今日还剩${QueryLimitManager.getRemainingQueries()}次免费查询`,
icon: "none",
duration: 2e3
});
taro.Taro.navigateTo({ url: "/pages/report/index" });
}
});
}