Commit 7adec80a authored by liuxinjun's avatar liuxinjun

添加视频成功和失败回调

parent 6a7544f5
...@@ -58,6 +58,11 @@ var sdk = { ...@@ -58,6 +58,11 @@ var sdk = {
userid: 0, userid: 0,
initFlag:0, initFlag:0,
//视频成功回调
videoSuccess:null,
//视频失败回调
videoFail:null,
/** /**
* @apiGroup A * @apiGroup A
* @apiName init * @apiName init
...@@ -1334,11 +1339,18 @@ var sdk = { ...@@ -1334,11 +1339,18 @@ var sdk = {
* *
* @apiSuccessExample {json} 示例: * @apiSuccessExample {json} 示例:
* //.参考文档:https://developers.weixin.qq.com/minigame/dev/document/ad/wx.createRewardedVideoAd.html * //.参考文档:https://developers.weixin.qq.com/minigame/dev/document/ad/wx.createRewardedVideoAd.html
* sdk.vedioSuccess = function(){
* //视频成功处理逻辑
* };
* sdk.vedioFail = function(){
* //视频失败处理逻辑
* };
* var videoAd = sdk.createRewardedVideoAd(); * var videoAd = sdk.createRewardedVideoAd();
* videoAd.load().then(() => videoAd.show()); * videoAd.load().then(() => videoAd.show());
* *
*/ */
createRewardedVideoAd(){ createRewardedVideoAd(){
let self = this;
if (cc.sys.platform === cc.sys.WECHAT_GAME) { if (cc.sys.platform === cc.sys.WECHAT_GAME) {
if(this.VideoAd){ if(this.VideoAd){
return this.VideoAd; return this.VideoAd;
...@@ -1347,6 +1359,22 @@ var sdk = { ...@@ -1347,6 +1359,22 @@ var sdk = {
this.VideoAd.onLoad(function(res){ this.VideoAd.onLoad(function(res){
console.log("sdk VideoAd广告加载事件:", res) console.log("sdk VideoAd广告加载事件:", res)
}); });
var closeFun = function(res){
// 用户点击了【关闭广告】按钮
// 小于 2.1.0 的基础库版本,res 是一个 undefined
if (res && res.isEnded || res === undefined) {
console.log("sdk 看视频成功");
self.videoSuccess();
}else {
console.error("sdk 看视频失败");
self.videoFail();
}
};
this.VideoAd.onClose(closeFun);
this.VideoAd.onError(function(res){ this.VideoAd.onError(function(res){
//console.log("sdk VideoAd广告错误事件:", res) //console.log("sdk VideoAd广告错误事件:", res)
wx.showToast({ wx.showToast({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment