AdAgent4399.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import AdAgent from "./AdAgent";
  2. import { BannerLocation } from "./YZ_Constant";
  3. import PlatUtils from "./PlatUtils";
  4. import { utils } from "./Utils";
  5. const { ccclass, property } = cc._decorator;
  6. /**
  7. * uc广告组件
  8. */
  9. @ccclass
  10. export default class AdAgent4399 extends AdAgent {
  11. _videoCallback: Function = null;
  12. _isVideoLoaded: boolean = false;
  13. _videoAd: any = null;
  14. //@ts-ignore
  15. _4399 = window.h5api;
  16. _canPlayAd: boolean = true;
  17. _remain: number = 0;
  18. public Init() {
  19. this.checkPlayAd();
  20. }
  21. /**
  22. * 获得是否可以播放广告及剩余次数
  23. */
  24. public checkPlayAd() {
  25. this._canPlayAd = true;
  26. return;
  27. // this._4399.canPlayAd((data: any) => {
  28. // if (data.canPlayAd) {
  29. // this._canPlayAd = data.canPlayAd;
  30. // } else {
  31. // this._canPlayAd = false;
  32. // }
  33. // if (data.remain) {
  34. // this._remain = data.remain;
  35. // }
  36. // utils.showLog("是否可播放广告", data.canPlayAd, "剩余次数", data.remain)
  37. // })
  38. }
  39. public ShowBanner() {
  40. utils.showLog("4399平台暂无banner广告");
  41. }
  42. public ShowInterstitial() {
  43. utils.showLog("4399平台暂时无插屏广告");
  44. }
  45. /**
  46. * 播放全屏广告
  47. * @param callback 播放广告时的广告状态回调函数
  48. */
  49. public ShowVideo(callback: Function) {
  50. if (PlatUtils.Is4399) {
  51. this._videoCallback = callback;
  52. if (this._canPlayAd) {
  53. this._4399.playAd((obj: any) => {
  54. utils.showLog('代码:' + obj.code + ',消息:' + obj.message)
  55. if (obj.code === 10000) {
  56. utils.showLog('视频开始播放')
  57. } else if (obj.code === 10001) {
  58. utils.showLog('视频播放结束')
  59. if (this._videoCallback) {
  60. this._videoCallback(true, "");
  61. this._videoCallback = null;
  62. }
  63. this.checkPlayAd();
  64. } else {
  65. if (this._videoCallback) {
  66. this._videoCallback(false, "激励视频异常!");
  67. this._videoCallback = null;
  68. }
  69. this.checkPlayAd();
  70. utils.showLog('视频广告异常')
  71. }
  72. })
  73. } else {
  74. utils.showLog('4399获取到不能播放广告! #this._canPlayAd=', this._canPlayAd, "剩余次数", this._remain);
  75. if (this._videoCallback) {
  76. this._videoCallback(false, "今日次数用完,明天再来!");
  77. this._videoCallback = null;
  78. }
  79. this.checkPlayAd();
  80. }
  81. }
  82. }
  83. }