Commit e682ab1b83597e691fd8b201b8670f83d1880bce
1 parent
d992823e
Exists in
master
and in
3 other branches
视频多例
Showing
5 changed files
with
67 additions
and
279 deletions
Show diff stats
sdk/shareTools.ts
... | ... | @@ -13,7 +13,7 @@ export class ShareTools { |
13 | 13 | * 验证分享:可处理成功、失败 |
14 | 14 | * @param shareKey |
15 | 15 | * @param params params.fail 有就不处理,没有自动处理 |
16 | - * @param opts 目前支持4个key 1,title自定义分享标题 2,img_url自定义分享图片 3,share_type(不走后台配置写死走视频or分享。1分享2视频3无视频则分享)4,closeSimulate是否关闭模拟分享 | |
16 | + * @param opts 目前支持5个key 1,title自定义分享标题 2,img_url自定义分享图片 3,share_type(不走后台配置写死走视频or分享。1分享2视频3无视频则分享)4,closeSimulate是否关闭模拟分享 5:multiton重新创建视频实例 | |
17 | 17 | */ |
18 | 18 | static share(shareKey: string, params?: { success?: Function, fail?: Function, context?: any }, opts?: any) { |
19 | 19 | if (typeof wx === 'undefined' || this.isTest) { |
... | ... | @@ -37,6 +37,16 @@ export class ShareTools { |
37 | 37 | } |
38 | 38 | })//this.buildParams(params) |
39 | 39 | } |
40 | + | |
41 | + /** | |
42 | + * 重新创建视频实例 | |
43 | + * @param shareKey | |
44 | + * @param params | |
45 | + * @param opts multiton重新创建视频实例 | |
46 | + */ | |
47 | + static multitonShare(shareKey: string, params?: { success?: Function, fail?: Function, context?: any }, opts?: any) { | |
48 | + this.share(shareKey, params, { multiton: true, ...opts }); | |
49 | + } | |
40 | 50 | /** |
41 | 51 | * 纯净分享 不处理回调 |
42 | 52 | * @param shareKey | ... | ... |
wxsdk/base/SDKConst.ts
wxsdk/service/GameService.ts
... | ... | @@ -159,16 +159,21 @@ export default class GameService { |
159 | 159 | }) |
160 | 160 | } |
161 | 161 | /** |
162 | - * 文本检测 | |
162 | + * 更换昵称和头像 | |
163 | 163 | */ |
164 | - updateNickname(nickname: string, headurl: string) { | |
164 | + updateNickname(nickname: string, headurl: string) { | |
165 | + let gameid = GAMEDATA.game_id; | |
166 | + let uid = DataService.I.UserId; | |
167 | + let token = DataService.I.Token; | |
168 | + let pkv = SDKVersion; | |
165 | 169 | return SDKApi.updateNickname({ |
166 | - ...this.buildParams(), | |
170 | + gameid,uid,token,pkv, | |
167 | 171 | nickname, headurl |
168 | 172 | }) |
169 | 173 | } |
170 | 174 | |
171 | 175 | |
176 | + | |
172 | 177 | /** |
173 | 178 | * 构建登录/弱登录公用参数 |
174 | 179 | */ | ... | ... |
wxsdk/service/ShareVideoService.ts
1 | -import { ShareVideoType, ShareVideoFrom } from "../base/SDKEnum"; | |
2 | -import RandomUtils from "../utils/RandomUtils"; | |
3 | -import ShareData from "./entity/ShareData"; | |
4 | -import SDKShare from "../share/SDKShare"; | |
5 | -import { __LOG__, GAMEDATA } from "../base/SDKConst"; | |
1 | +import { GAMEDATA } from "../base/SDKConst"; | |
2 | +import { ShareVideoType } from "../base/SDKEnum"; | |
6 | 3 | import { SDKApi } from "../http/SDKApi"; |
7 | -import DataService from "./DataService"; | |
4 | +import SDKShare from "../share/SDKShare"; | |
8 | 5 | import SDKVideo from "../share/SDKVideo"; |
6 | +import RandomUtils from "../utils/RandomUtils"; | |
7 | +import DataService from "./DataService"; | |
8 | +import ShareData from "./entity/ShareData"; | |
9 | 9 | |
10 | 10 | export default class ShareVideoService { |
11 | 11 | private forwardKey?: string; |
... | ... | @@ -27,26 +27,19 @@ export default class ShareVideoService { |
27 | 27 | this.forward(this.forwardKey); |
28 | 28 | } |
29 | 29 | |
30 | - private cnt: number = 1 | |
31 | - async initList() { //初始化List | |
30 | + async init() { | |
32 | 31 | let data = await SDKApi.ShareList(); |
33 | - if (data.code) { | |
34 | - console.log('拉取ShareList失败!') | |
35 | - setTimeout(this.initList.bind(this), 200 * this.cnt) | |
36 | - this.cnt++; | |
37 | - return | |
38 | - } | |
39 | 32 | this.setShareVideoData(data); |
40 | - if (this.forwardKey) this.forward(this.forwardKey); | |
41 | - } | |
42 | - async init() { | |
43 | - this.initList(); | |
33 | + // console.log(JSON.stringify(data)) | |
44 | 34 | SDKShare.I.updateShareMenu(true);//打开群分享 |
35 | + | |
45 | 36 | if (cc.sys.platform === cc.sys.WECHAT_GAME) { |
46 | 37 | if (GAMEDATA.shareMessageToFriend.scene > 0) { |
47 | 38 | wx.setMessageToFriendQuery({ shareMessageToFriendScene: GAMEDATA.shareMessageToFriend.scene }) |
48 | 39 | } |
49 | 40 | } |
41 | + | |
42 | + if (this.forwardKey) this.forward(this.forwardKey); | |
50 | 43 | } |
51 | 44 | |
52 | 45 | preload = true; |
... | ... | @@ -69,22 +62,26 @@ export default class ShareVideoService { |
69 | 62 | share_id: id, |
70 | 63 | query: this.createQuery({ share_key: key, share_id: id, query: opts.query }), |
71 | 64 | }; |
65 | + let multiton = false; | |
72 | 66 | if (opts) { |
73 | 67 | if (opts.title) _params.title = opts.title; |
74 | 68 | if (opts.img_url) _params.imageUrl = opts.img_url; |
75 | 69 | if (opts.share_type) typ = opts.share_type; |
70 | + if (opts.hasOwnProperty('multiton')) { | |
71 | + multiton = opts.multiton; | |
72 | + }; | |
76 | 73 | } |
77 | 74 | // console.log("share_query",JSON.stringify(_params), _params.query); |
78 | 75 | switch (+typ) { |
79 | 76 | case ShareVideoType.Video: |
80 | - SDKVideo.I.show(shareKey, videoid).then(success => { | |
77 | + SDKVideo.I.show(shareKey, videoid, multiton).then(success => { | |
81 | 78 | resolve(success) |
82 | 79 | }).catch(err => { |
83 | 80 | reject(err); |
84 | 81 | }) |
85 | 82 | break; |
86 | 83 | case ShareVideoType.VideoToShare: |
87 | - SDKVideo.I.show(shareKey, videoid).then(success => { | |
84 | + SDKVideo.I.show(shareKey, videoid, multiton).then(success => { | |
88 | 85 | resolve(success) |
89 | 86 | }).catch(err => { |
90 | 87 | if (err.code !== 1000 && err.code !== 1003) {//1000关闭1003正在播放 |
... | ... | @@ -110,46 +107,6 @@ export default class ShareVideoService { |
110 | 107 | resolve({}) |
111 | 108 | break; |
112 | 109 | } |
113 | - // share_desc = opts.shareTitle || share_desc; | |
114 | - // share_desc = StringUtils.stringFormat(share_desc, opts.formater); | |
115 | - // let shareMsg = { | |
116 | - // title: share_desc, | |
117 | - // imageUrl: opts.shareImg || share_icon, | |
118 | - // query | |
119 | - // }; | |
120 | - // // __LOG__ && console.error(`SDK ShareVideoService ${opts.shareForward ? 'forward 右上角分享:' : 'share 主动拉起分享:'}`); | |
121 | - // // __LOG__ && console.error(`SDK ShareVideoService 分享参数对象shareMsg: ${JSON.stringify(shareMsg)}`); | |
122 | - // // __LOG__ && console.error('SDK ShareVideoService 分享扩展参数', opts); | |
123 | - // DebugUtils.I.dynamic(`====> PCSDK ShareVideoService share 分享query: ${query}`); | |
124 | - // let success = (ret: any) => { | |
125 | - // // __LOG__ && console.error(`SDK ShareVideoService ${opts.shareForward ? 'forward 右上角分享:' : 'share 主动拉起分享:'} 成功回调: ${share_id}`); | |
126 | - // if (!opts.__GROUP) { | |
127 | - // // 不是群分享的情况下,进行统计,群分享需要验证 | |
128 | - // TempService.I.add(TempDataKeys.ShareSuccess, 1); | |
129 | - // share_id && LogService.I.tacticShare(share_id, share_key, TacticType.ShareSuccess); | |
130 | - // } | |
131 | - // resolve({ ...ret, share_id, share_key: shareKey }); | |
132 | - // }; | |
133 | - // let fail = (err: any) => { | |
134 | - // // __LOG__ && console.error(`SDK ShareVideoService ${opts.shareForward ? 'forward 右上角分享:' : 'share 主动拉起分享:'} 失败回调: ${share_id}`); | |
135 | - // if (!opts.__GROUP) { | |
136 | - // share_id && LogService.I.tacticShare(share_id, share_key, TacticType.ShareInterrupt); | |
137 | - // } | |
138 | - // reject({ ...err, share_id, share_key: shareKey }); | |
139 | - // }; | |
140 | - // if (opts.shareForward) | |
141 | - // // 右上角转发 | |
142 | - // Platform.I.forward(shareMsg, { | |
143 | - // ...opts, | |
144 | - // success, | |
145 | - // fail, | |
146 | - // context: this | |
147 | - // }); | |
148 | - // else | |
149 | - // // 普通分享 | |
150 | - // Platform.I.share(shareMsg, opts) | |
151 | - // .then((ret: any) => success(ret)) | |
152 | - // .catch((err: any) => fail(err)); | |
153 | 110 | }); |
154 | 111 | } |
155 | 112 | |
... | ... | @@ -166,129 +123,6 @@ export default class ShareVideoService { |
166 | 123 | // console.log("forward", JSON.stringify(params)); |
167 | 124 | SDKShare.I.forward(params); |
168 | 125 | } |
169 | - | |
170 | - /** | |
171 | - * 分享自动入口 | |
172 | - * @param shareKey | |
173 | - * @param opts { | |
174 | - * type: 当shareType为VideoAndShare时候,该参数有用,0:分享 1:视频 | |
175 | - * context: 函数执行上下文 | |
176 | - * fail: Function 失败函数 | |
177 | - * success: Function 成功函数 | |
178 | - * } | |
179 | - */ | |
180 | - // dispatch(shareKey: string, opts: any = {}, queryObj: { [key: string]: number | string } = {}) { | |
181 | - // let shareData = this.getShareVideoData(shareKey); | |
182 | - // let { share_open, share_wxad_id } = shareData; | |
183 | - // opts = { | |
184 | - // ...opts, | |
185 | - // share_wxad_id, | |
186 | - // __ShareData__: shareData | |
187 | - // }; | |
188 | - // this.dispatchType(+share_open, shareKey, opts, queryObj); | |
189 | - // } | |
190 | - | |
191 | - shareDispatch(shareKey: string, opts: any = {}, queryObj: { [key: string]: number | string } = {}) { | |
192 | - // this.dispatch(shareKey, opts, queryObj); | |
193 | - } | |
194 | - | |
195 | - /** | |
196 | - * 根据分享类型进行处理 | |
197 | - * @param shareType | |
198 | - * @param shareKey | |
199 | - * @param opts { | |
200 | - * type: 当shareType为VideoAndShare时候,该参数有用,0:分享 1:视频 | |
201 | - * context: 函数执行上下文 | |
202 | - * fail: Function 失败函数 | |
203 | - * success: Function 成功函数 | |
204 | - * } | |
205 | - */ | |
206 | - dispatchType(shareType: ShareVideoType, shareKey: string, opts: any = {}, queryObj: { [key: string]: number | string } = {}) { | |
207 | - // if (Platform.IsWx && OnlineService.I.getParamsInt(OnlineKeys.ShareUnlock, 1) !== 1) | |
208 | - // shareType = ShareVideoType.None; | |
209 | - | |
210 | - // let share_wxad_id = opts.share_wxad_id || (opts.__ShareData__ || this.getShareVideoData(shareKey) || {}).share_wxad_id; | |
211 | - // switch (shareType) { | |
212 | - // case ShareVideoType.None: // 无分享 | |
213 | - // this.handleSuccess(opts, shareType, ShareVideoFrom.None, null); | |
214 | - // break; | |
215 | - | |
216 | - // case ShareVideoType.Share: // 同步分享 | |
217 | - // // 同步分享点:是否开启后台配置中如果存在视频ID,则自动切换为视频点 | |
218 | - // if (opts.shareAutoVideo && share_wxad_id) { | |
219 | - // this.dispatchType(ShareVideoType.VideoToShare, shareKey, opts, queryObj); | |
220 | - // break; | |
221 | - // } | |
222 | - // this.group(shareKey, queryObj, opts) | |
223 | - // .then(ret => this.handleSuccess(opts, shareType, ShareVideoFrom.Share, ret)) | |
224 | - // .catch(err => this.handleFail(opts, shareType, ShareVideoFrom.Share, err)); | |
225 | - // break; | |
226 | - | |
227 | - // case ShareVideoType.ShareAysnc: // 异步分享 | |
228 | - // break; | |
229 | - | |
230 | - // case ShareVideoType.ShareIntegral: // 分享积分 | |
231 | - // // 是否开启分享积分,且配置为分享积分 | |
232 | - // if (IntegralService.I.IsOpen) { | |
233 | - // let data = IntegralService.I.convert(); | |
234 | - // if (data) { | |
235 | - // opts.shareIntegralData = data; | |
236 | - // this.dispatchType(data.shareType, shareKey, opts, queryObj); | |
237 | - // } else { | |
238 | - // // 超过了现在,直接执行失败:今日已达分享上限次数,请明日再来 | |
239 | - // this.handleFail(opts, shareType, ShareVideoFrom.Share, { ...ShareVideoError.ShareOverLimit }); | |
240 | - // } | |
241 | - // } else { | |
242 | - // // 如果配置了分享积分,但是未开启开关,则推:无视频则分享 | |
243 | - // this.dispatchType(ShareVideoType.VideoToShare, shareKey, opts, queryObj); | |
244 | - // } | |
245 | - // break; | |
246 | - | |
247 | - // case ShareVideoType.Video: // 看视频 | |
248 | - // Platform.I.video(shareKey, share_wxad_id) | |
249 | - // .then(ret => this.handleSuccess(opts, shareType, ShareVideoFrom.Video, ret)) | |
250 | - // .catch((err: any) => this.handleFail(opts, shareType, ShareVideoFrom.Video, err)); | |
251 | - // break; | |
252 | - | |
253 | - // case ShareVideoType.VideoToShare: // 无视频则分享 | |
254 | - // if (!share_wxad_id) { | |
255 | - // this.group(shareKey, queryObj, opts) | |
256 | - // .then(ret => this.handleSuccess(opts, shareType, ShareVideoFrom.Share, ret)) | |
257 | - // .catch(err => this.handleFail(opts, shareType, ShareVideoFrom.Share, err)); | |
258 | - // return; | |
259 | - // } | |
260 | - // Platform.I.video(shareKey, share_wxad_id) | |
261 | - // .then((ret) => this.handleSuccess(opts, shareType, ShareVideoFrom.Video, ret)) | |
262 | - // .catch((err: any) => { | |
263 | - // // 拉取视频失败/视频UID不存在/微信版本过低,暂不支持看视频,自动切换到分享 | |
264 | - // let { VideoFail, VideoInvalid, VideoNotOpen } = ShareVideoError; | |
265 | - // if (err && (err.code === VideoFail.code || err.code === VideoInvalid.code || err.code === VideoNotOpen.code)) | |
266 | - // this.group(shareKey, queryObj, opts) | |
267 | - // .then(ret => this.handleSuccess(opts, shareType, ShareVideoFrom.Share, ret)) | |
268 | - // .catch(err => this.handleFail(opts, shareType, ShareVideoFrom.Share, err)); | |
269 | - // else | |
270 | - // this.handleFail(opts, shareType, ShareVideoFrom.Video, err); | |
271 | - // }); | |
272 | - // break; | |
273 | - | |
274 | - // case ShareVideoType.VideoAndShare: // 看视频 | |
275 | - // if (share_wxad_id && opts.type === 1) { | |
276 | - // Platform.I.video(shareKey, share_wxad_id) | |
277 | - // .then(ret => this.handleSuccess(opts, shareType, ShareVideoFrom.Video, ret)) | |
278 | - // .catch((err: any) => this.handleFail(opts, shareType, ShareVideoFrom.Video, err)); | |
279 | - // } else { | |
280 | - // this.group(shareKey, queryObj, opts) | |
281 | - // .then(ret => this.handleSuccess(opts, shareType, ShareVideoFrom.Share, ret)) | |
282 | - // .catch(err => this.handleFail(opts, shareType, ShareVideoFrom.Share, err)); | |
283 | - // } | |
284 | - // break; | |
285 | - // } | |
286 | - } | |
287 | - | |
288 | - shareWithType(shareType: ShareVideoType, shareKey: string, opts: any = {}, queryObj: { [key: string]: number | string } = {}) { | |
289 | - this.dispatchType(shareType, shareKey, opts, queryObj); | |
290 | - } | |
291 | - | |
292 | 126 | /** |
293 | 127 | * 分享id |
294 | 128 | * @param shareKey |
... | ... | @@ -309,25 +143,6 @@ export default class ShareVideoService { |
309 | 143 | getShareVideoType(shareKey: string): ShareVideoType { |
310 | 144 | let shareData = this.getShareVideoData(shareKey); |
311 | 145 | let shareType: ShareVideoType = +shareData.typ; |
312 | - // // 木有开启分享,直接返回None | |
313 | - // if (Platform.IsWx && OnlineService.I.getParamsInt(OnlineKeys.ShareUnlock, 1) !== 1) | |
314 | - // return ShareVideoType.None; | |
315 | - | |
316 | - // // 后台配置视频,判断是否加载出错过,出错返回分享,否则直接返回 | |
317 | - // if (shareType === ShareVideoType.Video || shareType === ShareVideoType.VideoAndShare || shareType === ShareVideoType.VideoToShare) { | |
318 | - // // 检测视频加载失败 | |
319 | - // if (Platform.I.isVideoErrored()) | |
320 | - // return ShareVideoType.Share; | |
321 | - // else | |
322 | - // return shareType; | |
323 | - // } | |
324 | - | |
325 | - // // 是否开启分享积分,且配置为分享积分 | |
326 | - // if (shareType === ShareVideoType.ShareIntegral && IntegralService.I.IsOpen) { | |
327 | - // let data = IntegralService.I.convert(); | |
328 | - // if (data) | |
329 | - // return data.shareType; | |
330 | - // } | |
331 | 146 | return shareType; |
332 | 147 | } |
333 | 148 | |
... | ... | @@ -339,55 +154,6 @@ export default class ShareVideoService { |
339 | 154 | return this.getShareVideoType(shareKey); |
340 | 155 | } |
341 | 156 | |
342 | - private handleSuccess(opts: any, shareType: ShareVideoType, from: ShareVideoFrom, ret: any) { | |
343 | - // // 判断分享规则 | |
344 | - // if (IntegralService.I.IsOpen && opts.shareIntegralData && from === ShareVideoFrom.Share) { | |
345 | - // let shareNum = IntegralService.I.IntegralShareNum; | |
346 | - // if (shareNum === 0) { | |
347 | - // // 第1次分享 | |
348 | - // IntegralService.I.setIntegralShareNum(); | |
349 | - // IntegralService.I.resetShareRatio(); | |
350 | - // __LOG__ && console.error(`SDK ShareVideoService 分享积分 第1次分享: 初始来源:${shareType}, 类型:${from}, 分享次数:${shareNum}`); | |
351 | - // // 设定:第一次强制失败 | |
352 | - // // return this.handleFail(opts, shareType, from, { ...ShareVideoError.ShareRuleFail }, true); | |
353 | - // } else { | |
354 | - // // 第n次分享 | |
355 | - // IntegralService.I.setIntegralShareNum(); | |
356 | - // IntegralService.I.addShareRatio(); | |
357 | - | |
358 | - // let shareRatio = IntegralService.I.ShareRatio; | |
359 | - // let radomRatio = +Math.random().toFixed(2); | |
360 | - // __LOG__ && console.error(`SDK ShareVideoService 分享积分 第${shareNum}次分享: 初始来源:${shareType}, 类型:${from}, 分享次数:${shareNum}, 随机概率:${radomRatio}, 失败概率:${shareRatio}`); | |
361 | - // if (radomRatio <= shareRatio) { | |
362 | - // __LOG__ && console.error(`SDK ShareVideoService 分享积分 触发失败规则:分享强制失败, radomRatio <= shareRatio: ${radomRatio} <= ${shareRatio}`); | |
363 | - // return this.handleFail(opts, shareType, from, { ...ShareVideoError.ShareRuleFail }, true); | |
364 | - // } | |
365 | - // } | |
366 | - | |
367 | - // // 是否同步分享积分数据 | |
368 | - // let { intergral, isAsyncNum } = opts.shareIntegralData; | |
369 | - // isAsyncNum && LocalService.I.saveVideoOverShareNum(intergral); | |
370 | - // __LOG__ && isAsyncNum && console.error(`SDK ShareVideoService 分享积分 触发视频看完后,再次分享次数限制更新成功,成功后数量:${LocalService.I.getVideoOverShareNum(intergral)}`); | |
371 | - // } | |
372 | - | |
373 | - // let success = opts.success || function () { }; | |
374 | - // let context = opts.context || this; | |
375 | - // typeof success === 'function' && success.call(context, from, ret); | |
376 | - // (from === ShareVideoFrom.Share) && TempService.I.add(TempDataKeys.ShareSuccess, 1); | |
377 | - } | |
378 | - | |
379 | - private handleFail(opts: any, shareType: ShareVideoType, from: ShareVideoFrom, err: any, isFromIntegral?: boolean) { | |
380 | - // if (err instanceof Error) return; | |
381 | - // // 判断来自分享积分规则,则重置分享概率 | |
382 | - // if (IntegralService.I.IsOpen && opts.shareIntegralData && from === ShareVideoFrom.Share) { | |
383 | - // __LOG__ && console.error(`SDK ShareVideoService 强制失败分享,回滚到: ${IntegralService.I.ShareRatioInit}`); | |
384 | - // IntegralService.I.resetShareRatio(); | |
385 | - // } | |
386 | - // let fail = opts.fail || function () { }; | |
387 | - // let context = opts.context || this; | |
388 | - // fail && fail.call(context, from, err); | |
389 | - } | |
390 | - | |
391 | 157 | private setShareVideoData(data: any) { |
392 | 158 | (data.data || []).forEach((item: any) => { |
393 | 159 | this.shareObjs[item.key] = this.shareObjs[item.key] || []; |
... | ... | @@ -399,10 +165,6 @@ export default class ShareVideoService { |
399 | 165 | let list: Array<ShareData> = this.shareObjs[shareKey]; |
400 | 166 | if (!list) { |
401 | 167 | list = this.shareObjs.default; |
402 | - // let shareData: ShareData = CfgManager.I.config.ShareData; | |
403 | - // if (!shareData) throw new TypeError('SDK ShareVideoService - 请在config.js中配置ShareData'); | |
404 | - // let share_open = shareData.share_wxad_id ? ShareVideoType.Video : ShareVideoType.Share; | |
405 | - // return { ...shareData, share_id: 99999 + '', share_key: shareKey, share_open }; | |
406 | 168 | } |
407 | 169 | let index = RandomUtils.rand(0, list.length); |
408 | 170 | return list[index]; | ... | ... |
wxsdk/share/SDKVideo.ts
... | ... | @@ -8,6 +8,7 @@ import LogService from "../service/LogService"; |
8 | 8 | export default class SDKVideo { |
9 | 9 | private _isPlaying: boolean; |
10 | 10 | private _isErrored: boolean; |
11 | + private _isMultiton: boolean; | |
11 | 12 | private resolve: any; |
12 | 13 | private reject: any; |
13 | 14 | private videoAd: any; |
... | ... | @@ -19,6 +20,7 @@ export default class SDKVideo { |
19 | 20 | this.videoKey = ''; |
20 | 21 | this._isPlaying = false; |
21 | 22 | this._isErrored = false; |
23 | + this._isMultiton = false; | |
22 | 24 | } |
23 | 25 | |
24 | 26 | get isErrored() { |
... | ... | @@ -35,7 +37,7 @@ export default class SDKVideo { |
35 | 37 | if (this.preloadVideoAd || this.isPreload) return |
36 | 38 | this.isPreload = true; |
37 | 39 | let ad = wx.createRewardedVideoAd({ |
38 | - adUnitId | |
40 | + adUnitId, | |
39 | 41 | }); |
40 | 42 | ad.onError(this.preError); |
41 | 43 | ad.load().then(this.handleLoaded2).catch(() => { |
... | ... | @@ -54,8 +56,6 @@ export default class SDKVideo { |
54 | 56 | that.preloadVideoAd = that.videoAd2; |
55 | 57 | that.isPreload = false |
56 | 58 | __LOG__ && console.warn("视频预加载成功", that.preloadVideoAd) |
57 | - // that.preloadVideoAd.ttttttt = '111111' | |
58 | - // console.warn(that.preloadVideoAd.isReady()); | |
59 | 59 | } |
60 | 60 | |
61 | 61 | offPreload() { |
... | ... | @@ -63,7 +63,14 @@ export default class SDKVideo { |
63 | 63 | that.preloadVideoAd.offError(that.preError); |
64 | 64 | } |
65 | 65 | |
66 | - async show(videoKey: string, adUnitId: string): Promise<any> { | |
66 | + /** | |
67 | + * | |
68 | + * @param videoKey | |
69 | + * @param adUnitId | |
70 | + * @param multiton 多例 | |
71 | + * @returns | |
72 | + */ | |
73 | + async show(videoKey: string, adUnitId: string, multiton: boolean = false): Promise<any> { | |
67 | 74 | return new Promise(async (resolve, reject) => { |
68 | 75 | if (this.isPlaying) |
69 | 76 | return reject({ ...ShareVideoError.VideoPlaying }); |
... | ... | @@ -72,26 +79,23 @@ export default class SDKVideo { |
72 | 79 | return reject({ ...ShareVideoError.VideoInvalid }); |
73 | 80 | |
74 | 81 | LogService.I.adStat(videoKey, this.adUnitId, DOT_AD_TYPE.video, DOT_AD_STATUS.request); |
75 | - let videoAd | |
76 | - let hasVideo | |
77 | - if (this.preloadVideoAd) { | |
82 | + let videoAd; | |
83 | + let hasVideo; | |
84 | + if (this.preloadVideoAd && !multiton) { | |
78 | 85 | __LOG__ && console.log("使用预加载视频", this.preloadVideoAd) |
79 | 86 | hasVideo = true |
80 | - this.offPreload() | |
87 | + this.offPreload(); | |
81 | 88 | videoAd = this.preloadVideoAd; |
82 | - this.preloadVideoAd = null; | |
83 | - // this.preloadVideo(adUnitId); | |
84 | 89 | } else { |
85 | 90 | __LOG__ && console.log("不使用预加载视频") |
86 | - hasVideo = false | |
91 | + hasVideo = false; | |
87 | 92 | videoAd = wx.createRewardedVideoAd({ |
88 | - adUnitId | |
93 | + adUnitId, | |
94 | + multiton: true | |
89 | 95 | }); |
90 | 96 | // this.preloadVideo(adUnitId); |
91 | 97 | } |
92 | - // let videoAd = wx.createRewardedVideoAd({ | |
93 | - // adUnitId | |
94 | - // }); | |
98 | + this._isMultiton = !hasVideo; | |
95 | 99 | if (!videoAd) |
96 | 100 | return reject({ ...ShareVideoError.VideoNotOpen }); |
97 | 101 | |
... | ... | @@ -101,7 +105,6 @@ export default class SDKVideo { |
101 | 105 | this.adUnitId = adUnitId; |
102 | 106 | this.resolve = resolve; |
103 | 107 | this.reject = reject; |
104 | - | |
105 | 108 | this.videoAd = videoAd; |
106 | 109 | videoAd.onClose(this.handleClose); |
107 | 110 | videoAd.onError(this.onError); |
... | ... | @@ -123,7 +126,6 @@ export default class SDKVideo { |
123 | 126 | } |
124 | 127 | |
125 | 128 | } |
126 | - this.preloadVideo(adUnitId); | |
127 | 129 | __LOG__ && console.warn('====> PCSDK WxVideo 请求视频adUnitId', adUnitId); |
128 | 130 | }); |
129 | 131 | } |
... | ... | @@ -140,8 +142,8 @@ export default class SDKVideo { |
140 | 142 | // __LOG__ && console.warn("handleLoaded2", that.videoAd, that.videoAd.isReady()); |
141 | 143 | LogService.I.adStat(this.videoKey, this.adUnitId, DOT_AD_TYPE.video, DOT_AD_STATUS.show) |
142 | 144 | |
143 | - if (cc.sys.platform === cc.sys.WECHAT_GAME && typeof qq == 'undefined') { | |
144 | - if (that.videoAd.isReady()) {//抖音、qq 没有 isReady | |
145 | + if (cc.sys.platform === cc.sys.WECHAT_GAME) { | |
146 | + if (that.videoAd.isReady()) {//抖音没有 isReady | |
145 | 147 | that.show_time = Date.now(); |
146 | 148 | await that.videoAd.show(); |
147 | 149 | } else { |
... | ... | @@ -178,6 +180,15 @@ export default class SDKVideo { |
178 | 180 | that.reject && that.reject({ ...ShareVideoError.VideoQuit }); |
179 | 181 | } |
180 | 182 | that.videoAd.offClose(that.handleClose); |
183 | + if (that._isMultiton) { | |
184 | + that.videoAd.destroy(); | |
185 | + that.videoAd = null; | |
186 | + } | |
187 | + // if (that.preloadVideoAd) { | |
188 | + // that.preloadVideoAd.destroy(); | |
189 | + // that.preloadVideoAd = null; | |
190 | + // } | |
191 | + that.preloadVideo(that.adUnitId); | |
181 | 192 | that._isPlaying = false; |
182 | 193 | that._isErrored = false; |
183 | 194 | } | ... | ... |