TVCanvas.js 81.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622
var Common = require('Common');
var Network = require('Network');
var TVFocus = require('TVFocus');
var FocusInfo = require('FocusInfo');
//var ListCell= require('ListCell');
var BusinessParameter = require('BusinessParameter');
var Application = require('Application');
var Log = require('Log');


cc.Topdraw = cc.Topdraw || {};
cc.Topdraw.TVCanvas =
    cc.Class({
        extends: cc.Component,

        properties: {

            //如果成功了要添加 
            //Log 版块
            _cLog: null,
            _cApplication: null,
            _cFocus: null,

            _aFocusTargets: [], //可被聚焦的块集合 分成状态区

            _fiCurrentFocus: null,
            _iSceneStatus: 0, //场景状态 和焦点寻找有关系
            _fFocusScaleFactor: 1.06, //焦点缩放因数


            //数据初始化状态
            _bIsFocusInit: false,
            //_bIsNavigatorDataInit:false,
            //_bIsFeaturePromotionDataInit:false,
            //_bIsBackgroundDataInit:false,

            //_iCurrentFeatureBuffer:1,

            _oSceneContext: null, //当前场景的上下文,用于后续恢复
            //_oCurrentSceneParameter:null, //去下一个场景的参数
            _oNextSceneParameter: null, //去下一个场景的参数


            //结构大概如下,主要用于手机上模拟测试
            //["idxxxx" :{"startX":,"startY":,"status":"touching 或 untouching"},

            //]

            _compPlayer: null,
            _aTouchContext: [],

            _defaultBackScene: null,//每个场景Canvas都有的 默认返回场景 每个场景自己构造函数内设置值 
            _oFocusScaleFactorInfo: null,

            _bShowExitBox: false,

        },
        onLoad: function () {

            try {
                //Common.DEBUG_MODE=1;
                cc.log(cc.director.getScene().name + " Loaded!!!");
                //释放资源
                Common.g_oRomoteURLTexture = {};
                //Common.g_oTextureInUsage = {};
                cc.g_oUsedPrefabPaths = {};//todo:不知道该挂到哪里了,这么做好想太任性了
                //重写cc.director.loadscene应该是有用的吧
                let temp = cc.director.loadScene;
                let self = this;
                cc.game.resume();
                cc.director.loadScene = function (strSceneName, oExtra) {
                    //把背景提上来
                    if (self.node) {
                        self.node.opacity = 0;
                    }
                    self._oProbe.requestProbe("interActive");
                    self._oProbe.requestProbe("UILeave", oExtra || {});

                    cc.game.pause();
                    for (let key in Common.g_oRomoteURLTexture) {
                        if (Common.g_oRomoteURLTexture[key]) {
                            cc.loader.release(Common.g_oRomoteURLTexture[key]);
                            delete Common.g_oRomoteURLTexture[key];
                        }
                    }
                    //cc.sys.garbageCollect();
                    temp.call(cc.director, strSceneName);
                    cc.director.loadScene = temp;
                }
                //页面更新定时器
                this.updateTimer4Page = 0;
                this.updateInterval4Page = 1;
                //通用更新定时器
                this.updateTimer = 0;
                this.updateInterval = 1;
                //定时GC 20s一次
                this.updateTimer4GC = 0;
                this.updateInterval4GC = 20;

                //定时GC 20次按键一次
                this._iKeyDownCount4GC = 20;
                this._iKeyDownCount = 0;

                Common.g_strCurrentSceneName = cc.director.getScene().name;

                //标记图片渲染批次
                Common.g_iImageRenderBatchNo = 0;

                //初始加载图片记录对象
                this._oRemoteImageRequestInfo = {};

                //获得应用级别的上下文状态
                if (cc.find('application')) {
                    this._cApplication = cc.find('application').getComponent(Application);
                } else {
                    //数据初始化
                    if (cc.sys.isNative) {
                        //获取APITOKEN
                        // Common.API_TOKEN = jsb.reflection.callStaticMethod("com/topdraw/melody/TopdrawSDKWrapper", "getAPIToken", "()Ljava/lang/String;");
                        // Common.TEST_API_TOKEN = Common.API_TOKEN || Common.TEST_API_TOKEN;

                        cc.log("Token in JS:" + Common.API_TOKEN);

                        //获取用户id
                        // Common.USER_ID = jsb.reflection.callStaticMethod("com/topdraw/melody/TopdrawSDKWrapper", "getUserId", "()Ljava/lang/String;") || 'someone';

                        //鉴权                                                                                        ILjava/lang/String;
                        // jsb.reflection.callStaticMethod("com/topdraw/melody/TopdrawSDKWrapper", "auth", "(Ljava/lang/String;)V", "onGetAuthInfo");   //这里需要修改参数,添加上mediaID

                        //获取播放地址测试
                        //let o1 = jsb.reflection.callStaticMethod("com/topdraw/melody/TopdrawSDKWrapper", "getPlayURL", "(ILjava/lang/String;)V", 2193, "onGetPlayURL");
                    }
                    let nodeApplication = new cc.Node('application');
                    cc.game.addPersistRootNode(nodeApplication);
                    this._cApplication = nodeApplication.addComponent(Application);
                }
                this._oProbe = this._cApplication._oProbe;
                this._cApplication.setScene(this);
                //进入页面探针
                this._oProbe.requestProbe("UIEnter");
                //设置背景为透明
                //cc.director.setClearColor(cc.Color.TRANSPARENT);
                cc.Camera.main.backgroundColor = cc.Color.TRANSPARENT;
                cc.macro.ENABLE_WEBGL_ANTIALIAS = true;

                this._oSceneContext = {};
                this._oNextSceneParameter = {};

                //以后再考虑是否用这种做法
                //this.node.on('focus_leave', this.onFocusLeave,this);
                //this.node.on('focus_hover', this.onFocusHover,this);

                //初始化焦点临接表
                if (null == this._aFocusTargets[0]) {
                    this._aFocusTargets[0] = [];
                }


                this._iFocusStatus = 0;
                //这里很业务啊是不是应该放这里
                //获取收藏夹id

                if (cc.sys.isNative) {
                    //隐藏java端的loading界面
                    // jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "removeLaunchImage", "()V");
                }

                //请求页面探针
                try {
                    // this.sceneBIProbe();
                } catch (err) {

                }

                //创建Log节点
                let nodeLog = new cc.Node('Log');
                this._cLog = nodeLog.addComponent(Log);
                this._cLog.init(this);
                this.node.addChild(nodeLog, 20);
                nodeLog.opacity = 0;
                nodeLog.angle = -90;

                this._cLog.screenI("启动当前场景: " + cc.director.getScene().name);

                //注册键盘事件
                cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
                cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP, this.onKeyUp, this);


                //注册摸来摸去事件
                this.node.on('touchstart', this.onTouchStart, this);
                this.node.on('touchmove', this.onTouchMove, this);
                this.node.on('touchend', this.onTouchEnd, this);

                this.node.on('before_focus_change', this.onBeforeFocusChange, this);
                this.node.on('after_focus_change', this.onAfterFocusChange, this);


                this.node.on('focus', this.onFocus, this);
                this.node.on('blur', this.onBlur, this);
            } catch (error) {
                if (cc.sys.isNative) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "onLoad Error in TVCanvas==>" + error);
                }
            }

        },
        onKeyUp: function (event) {
            try {
                //cc.log('OnKeyUp In TVCanvas');
                if (!this._bIsFocusInit) {
                    return;
                }
            } catch (error) {
                if (cc.sys.isNative) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "onKeyUp Error in TVCanvas==>" + error);
                }
            }

        },
        onKeyDown: function (event) {
            try {
                if (!this._bIsFocusInit) {
                    return;
                }
                this.updateTimer4GC = 0;
                this._iKeyDownCount++;
                if (this._iKeyDownCount % this._iKeyDownCount4GC == 0) {
                    //this._cLog.screenI("GC:20次按键操作后执行");
                    //cc.sys.garbageCollect();
                }
                //cc.log('OnKeyDown In TVCanvas');

                let nodeLog = null;
                this._cLog.screenI("event.keyCode==>" + event.keyCode);
                //检测debug模式
                let strDebugKey = Common.g_aDebugKey[Common.g_iDebugIndex];
                if (event.keyCode == cc.macro.KEY[strDebugKey] || event.keyCode == Common.ANDROID_KEY[strDebugKey]) {
                    Common.g_iDebugIndex++;
                } else {
                    Common.g_iDebugIndex = 0;
                }
                if (Common.g_iDebugIndex == Common.g_aDebugKey.length) {
                    this._cLog.screenI((Common.DEBUG_MODE ? "打开" : "关闭") + "DEBUG模式!");
                    Common.DEBUG_MODE = !Common.DEBUG_MODE;
                    this.commonSimpleTip("打开DEBUG模式!");
                    // this._cLog.node.opacity = Common.DEBUG_MODE * 255;   //这里先注释所有界面的日志显示,只保留全局debug效果,    fix jerry
                    // Common.g_iDebugIndex = 0;
                    // if (Common.DEBUG_MODE) {
                    //     this.checkUpdateManifest();
                    // }
                }
                switch (event.keyCode) {

                    case cc.macro.KEY.t:
                        nodeLog = this.node.getChildByName('Log');
                        //nodeLog.active=!(nodeLog.active);
                        nodeLog.opacity = ((nodeLog.opacity == 0) ? 255 : 0);

                        this._cLog.screenD('....日志测试Test-' + nodeLog.opacity + '-a');
                        this._cLog.screenI('....日志测试Test-' + nodeLog.opacity + '-b');
                        this._cLog.screenW('....日志测试Test-' + nodeLog.opacity + '-c');
                        this._cLog.screenE('....日志测试Test-' + nodeLog.opacity + '-d');
                        break;
                }
            } catch (error) {
                if (cc.sys.isNative) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "onKeyDown Error in TVCanvas==>" + error);
                }
            }

        },
        onTouchStart: function (event) {

            cc.log('OnTouchStart In TVCanvas');
        },
        onTouchMove: function (event) {

            cc.log('OnTouchMove In TVCanvas');
        },
        onTouchEnd: function (event) {

            cc.log('OnTouchEnd In TVCanvas');
        },
        setCurrentFocus: function (fiCurrentFocus) {
            try {
                this._fiCurrentFocus = fiCurrentFocus;
            } catch (error) {
                if (cc.sys.isNative) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "setCurrentFocus Error in TVCanvas==>" + error);
                }
            }

        },

        /**
         * 返回上一个场景
         */
        backAScene: function () {
            try {
                var self = this;
                if (!this._bIsFocusInit) {
                    return;
                }
                this._ComOperation && this._ComOperation.end();//有播放器的话,先把播放器释放掉
                let bRemoteImageRequestCompleted = true;
                for (let key in this._oRemoteImageRequestInfo) {
                    if (this._oRemoteImageRequestInfo[key] == "loading") {
                        bRemoteImageRequestCompleted = false;
                    }
                    break;
                }
                let oExtra = {
                    "linkPoint": { "type": "back" },
                }
                //上下文
                let compApplication = cc.find('application').getComponent(Application);
                let aSceneContext = compApplication.getSceneContext();
                let aSceneParameter = compApplication.getSceneParameter();
                if (aSceneParameter.length) {
                    this._bShowExitBox = false;
                    let oSceneParameter = aSceneParameter.pop();
                    //aSceneParameter[]
                    compApplication.setBackStatus(true);
                    if (!oSceneParameter.backSceneName) {
                        oSceneParameter.backSceneName = "sceneDefault4Back";
                    }
                    if (oSceneParameter.backSceneName == "sceneExitApp") {
                        this._cLog.screenI("应该退出应用才对1");
                        //cc.director.end();
                        cc.game.end();
                    } else if (oSceneParameter.backSceneName == "sceneDefault4Back") {
                        if (!this._oDefaultBackASceneParameter || this._oDefaultBackASceneParameter.backSceneName == "sceneExitApp") {
                            this._cLog.screenI("应该退出应用才对2");
                            //cc.director.end();
                            cc.game.end();
                        } else {
                            aSceneContext.push(this._oDefaultBackASceneContext || null);
                            Common.g_strCurrentSceneName = this._oDefaultBackASceneParameter.backSceneName;
                            cc.director.loadScene(this._oDefaultBackASceneParameter.backSceneName, oExtra);
                        }
                    } else {
                        Common.g_strCurrentSceneName = oSceneParameter.backSceneName;
                        cc.director.loadScene(oSceneParameter.backSceneName, oExtra);
                    }
                } else {
                    if (this._oDefaultBackASceneParameter) {
                        compApplication.setBackStatus(true);
                        if (this._oDefaultBackASceneParameter.backSceneName == "sceneExitApp") {
                            cc.log("应该退出应用才对3");
                            //cc.director.end();
                            cc.game.end();
                        } else {
                            aSceneContext.push(this._oDefaultBackASceneContext || null);
                            Common.g_strCurrentSceneName = this._oDefaultBackASceneParameter.backSceneName;
                            cc.director.loadScene(this._oDefaultBackASceneParameter.backSceneName, oExtra);
                        }
                    } else {
                        cc.log("应该退出应用才对4");
                        //cc.director.end();
                        // this.commonSimpleTip("退出应用", 1);
                        // cc.game.end();

                        if (!this._bShowExitBox) {    //弹出挽留界面
                            this.showDetainBox();
                        } else {
                            cc.log("退出应用5!");
                            self.commonSimpleTip("正在退出...", 3000, 0, -320);
                            if (cc.sys.isNative) {  //通知福建移动埋点SDK退出应用
                                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "onExitApp", "()V");
                            }
                            setTimeout(function () {
                                cc.game.end();
                            }.bind(this), 3500);  //延时销毁可以让福建移动埋点SDK发送出去                       
                        }
                    }
                }
            } catch (error) {
                if (cc.sys.isNative) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "backAScene Error in TVCanvas==>" + error);
                }
            }

        },
        doTVLinkAction: function (oOperation) {
            try {
                //cc.game.addPersistRootNode(nodeApplication.addComponent(Application));
                let nodeApplication = cc.find('application').getComponent(Application);

                //if (nodeApplication){
                let aSceneContext = nodeApplication.getSceneContext();
                //let oSceneContext={};
                let aSceneParameter = nodeApplication.getSceneParameter();
                //let oSceneParameter={};
                //}
                let fnCallback;
                let strForwardSceneName = "";
                this._oNextSceneParameter.backSceneName = cc.director.getScene().name;
                this._oSceneContext.focusPath = this._fiCurrentFocus && Common.getNodePath(this._fiCurrentFocus.node);


                switch (oOperation.action) {
                    case "onSystemPromptConfirmClick":
                        this._cLog.screenI("cc.macro.KEY.enter onSystemPromptConfirmClick" + Common.TV_LINK_ACTION_CLICK);
                        this._ComOperation && this._ComOperation.end();
                        this.backAScene();
                        return;
                        break;
                    case "onSystemPromptCancelClick":
                        this.hideDetainBox();
                        return;
                        break;
                    case "onComingSoonConfirmClick":
                    case "onComingSoonCancelClick":
                        this.hideComingSoonBox();
                        return;
                        break;
                    case "exit":
                        cc.game.end();
                        break;
                    case "ChangeScene":
                        //离开页面探针

                        strForwardSceneName = oOperation.parameters.sceneName;
                        fnCallback = function () {
                            for (let key in oOperation.parameters) {
                                if (null != oOperation.parameters[key] && '' != oOperation.parameters[key])
                                    this._oNextSceneParameter[key] = oOperation.parameters[key];
                            }
                            if (null != strForwardSceneName && 0 < strForwardSceneName.length) {
                                this._oNextSceneParameter.sceneName = strForwardSceneName;
                                aSceneParameter.push(this._oNextSceneParameter);
                                aSceneContext.push(this._oSceneContext);
                                this._ComOperation && this._ComOperation.end();
                                Common.g_strCurrentSceneName = strForwardSceneName;
                                cc.director.loadScene(strForwardSceneName);
                            }
                        }
                        //加个播放列表上限判断
                        //在跳播放器的情况下,需要添加歌曲到播放列表时,超出上限要提示
                        if (strForwardSceneName == 'sceneVideoPlayer' || strForwardSceneName == 'sceneKTVPlayer' || strForwardSceneName == 'sceneAudioPlayer') {
                            oOperation.parameters.appId = oOperation.parameters.appId || this._strAppId;
                        }
                        if (strForwardSceneName
                            && (strForwardSceneName == 'sceneVideoPlayer' || strForwardSceneName == 'sceneKTVPlayer')
                            && oOperation.parameters.mediaId
                            && !oOperation.parameters.bFree
                        ) {
                            this.checkPlaylistCount(this._strAppId, 1, function () {
                                if (this._iPlaylistItemTotalCount >= Common.PLAY_LIST_ITEM_COUNT_LIMIT) {
                                    delete oOperation.parameters.mediaId;
                                }
                                fnCallback && fnCallback.call(this);
                            }, true);
                        } else {
                            fnCallback && fnCallback.call(this);
                        }
                        return;
                        break;

                    case "promotionBIProbe":
                        this.promotionBIProbe(oOperation.parameters.id);
                        break;
                    default:
                        break;
                }
                this._cLog.screenI(strForwardSceneName);
                if (null != strForwardSceneName && 0 < strForwardSceneName.length) {
                    this._oNextSceneParameter.sceneName = strForwardSceneName;
                    aSceneParameter.push(this._oNextSceneParameter);
                    aSceneContext.push(this._oSceneContext);
                    // this._cLog.screenI("跳转场景1111111");
                    this._ComOperation && this._ComOperation.end();
                    // this._cLog.screenI("跳转场景2222222");
                    Common.g_strCurrentSceneName = strForwardSceneName;
                    cc.director.loadScene(strForwardSceneName);
                }
            } catch (error) {
                if (cc.sys.isNative) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "doTVLinkAction Error in TVCanvas==>" + error);
                }
            }
        },
        addNodeToFocusTarget: function (iStatus, strKey, nodeFocusable) {
            try {
                this._aFocusTargets[iStatus][strKey] = nodeFocusable;
            } catch (error) {
                if (cc.sys.isNative) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "addNodeToFocusTarget Error in TVCanvas==>" + error);
                }
            }

        },
        getFocus: function () {
            try {
                return this._cFocus;
            } catch (error) {
                if (cc.sys.isNative) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "getFocus Error in TVCanvas==>" + error);
                }
            }

        },
        getCurrentFocusInfo: function () {
            try {
                return this._fiCurrentFocus;
            } catch (error) {
                if (cc.sys.isNative) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "getCurrentFocusInfo Error in TVCanvas==>" + error);
                }
            }

        },
        getFocusTargets: function () {
            try {
                return this._aFocusTargets;
            } catch (error) {
                if (cc.sys.isNative) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "getFocusTargets Error in TVCanvas==>" + error);
                }
            }


        },
        onFocus: function (event) {
            try {
                let fiFrom = event.detail.from;
                let fiTo = event.detail.to;
                fiTo.onFocus(fiFrom);
            } catch (error) {
                if (cc.sys.isNative) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "onFocus Error in TVCanvas==>" + error);
                }
            }

        },
        onBlur: function (event) {
            try {
                let fiFrom = event.detail.from;
                let fiTo = event.detail.to;
                fiFrom && fiFrom.onBlur(fiTo);
            } catch (error) {
                if (cc.sys.isNative) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "onBlur Error in TVCanvas==>" + error);
                }
            }


        },

        /**
         * 仅供测试使用
         * @param strPlayURL 回调后得到的播放地址
         * 
         */
        onGetPlayURL: function (options) {
            try {
                this._cLog.screenI("拿到播放播放地址" + options);
                this._ComOperation.setURL(JSON.parse(options));
            } catch (error) {
                if (cc.sys.isNative) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "onGetPlayURL Error in TVCanvas==>" + error);
                }
            }

        },

        /*推荐位BI探针*/
        createPromotionBIProbeAction: function (strTVLink, strId) {
            try {
                let joTVLink = JSON.parse(strTVLink);
                joTVLink.click = joTVLink.click || [];
                joTVLink.click.push({ "action": "promotionBIProbe", "parameters": { "id": strId } });
                return JSON.stringify(joTVLink);
            } catch (error) {
                if (cc.sys.isNative) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "createPromotionBIProbeAction Error in TVCanvas==>" + error);
                }
            }

        },
        promotionBIProbe: function (strPromotionId) {
            try {
                //为了BI方便统计,做些变形
                let strBIURL = './NoPage/TopdrawPromotion?id=' + strPromotionId;//todo:这个地址其实还不确定
                let oParams = {
                    "platformAccount": Common.USER_ID,
                    "url": strBIURL,
                };
                Network.ajax('GET', Common.BI_BASE_PATH, null, oParams,
                    function (strResponse) {
                        try {
                            let oJSONResult = JSON.parse(strResponse);
                            if (oJSONResult.businessCode == "success") {
                                cc.log("Business Success : Promotion BI Probe Request Success");
                            } else {
                                cc.log("Business Error : Promotion BI Probe Request failed..." + oJSONResult.description);
                            }
                        } catch (ex) {
                            cc.log("Business Exception : Promotion BI Probe Request Error.." + ex);
                        }
                    },
                    function (strResponse) {
                        cc.log("Communication Error : Promotion BI Probe Request Error..." + strResponse + "\r\n");
                    }, this, "uuid"
                );
            } catch (error) {
                if (cc.sys.isNative) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "promotionBIProbe Error in TVCanvas==>" + error);
                }
            }
        },

        /*场景BI探针*/
        sceneBIProbe: function () {
            try {
                //场景参数
                let oSceneParameter = this._cApplication.getTopSceneParameter() || {};

                let strCurSceneName = cc.director.getScene().name;
                let strCurURL = strCurSceneName + "?";

                let oBIParameter = {};
                for (let key in oSceneParameter) {
                    if (key != "sceneName") {
                        strCurURL += (key + "=" + oSceneParameter[key] + "&");
                    }
                }
                strCurURL += ("timeStamp=" + new Date().getTime() + "&");
                strCurURL += ("backStatus=" + (this._cApplication.getBackStatus() ? 1 : 0) + "&");
                strCurURL = strCurURL.substring(0, strCurURL.length - 1);
                //附加参数
                oBIParameter.platformAccount = Common.USER_ID;
                oBIParameter.url = encodeURIComponent(strCurURL);
                oBIParameter.referURL = oSceneParameter.backSceneName || "";


                Network.ajax('GET', Common.BI_BASE_PATH, null, oBIParameter,
                    function (strResponse) {
                        try {
                            var oJSONResult = JSON.parse(strResponse);
                            if (oJSONResult.businessCode == "success") {
                                cc.log("Business Success : Page BI Probe Request Success");
                            } else {
                                cc.log("Business Error : Page BI Probe Request failed..." + oJSONResult.description);
                            }
                        } catch (ex) {
                            cc.log("Business Exception : Page BI Probe Request Error.." + ex);
                        }
                    },
                    function (strResponse) {
                        cc.log("Communication Error : Page BI Probe Request Error..." + strResponse + "\r\n");
                    }, this, "uuid"
                );
            } catch (error) {
                if (cc.sys.isNative) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "sceneBIProbe Error in TVCanvas==>" + error);
                }
            }
        },

        /**
         * 获取页面背景
         * @param node4Empty 挖空区域,以节点尺寸位置做参考,有就挖空,没有就不挖空
         * @param strCategoryId 分类节点id
         * @param strImageTag 图片标签 默认background
         * @param iIndex 标签图片索引
         */
        getPageBg: function (node4Empty, info4RemoteImg, localImgPath, strAppId) {
            try {
                let strCategoryId = info4RemoteImg[0];
                let strImageTag = info4RemoteImg[1];
                let iIndex = info4RemoteImg[2];
                let nodeBgMask = this.node.getChildByName("BackgroundMask") || new cc.Node("BackgroundMask");
                let maskBg = nodeBgMask.getComponent(cc.Mask) || nodeBgMask.addComponent(cc.Mask);
                let nodeBg = this.node.getChildByName("Background") || new cc.Node("Background");
                let spriteBg = nodeBg.getComponent(cc.Sprite) || nodeBg.addComponent(cc.Sprite);
                let iPositionX = node4Empty && Common.getX(node4Empty) || 0;
                let iPositionY = node4Empty && Common.getY(node4Empty) || 0;
                nodeBgMask.width = node4Empty && node4Empty.width || 0;
                nodeBgMask.height = node4Empty && node4Empty.height || 0;
                nodeBgMask.x = iPositionX;
                nodeBgMask.y = iPositionY;
                nodeBgMask.zIndex = -1;
                maskBg.inverted = true;
                nodeBg.width = Common.SCREEN_WIDTH;
                nodeBg.height = Common.SCREEN_HEIGHT;
                nodeBg.x = -iPositionX;
                nodeBg.y = -iPositionY;
                nodeBgMask.parent = this.node;
                nodeBg.parent = nodeBgMask;
                //后台配置
                if (!strCategoryId && localImgPath) {
                    Common.renderSpriteByLocalImage(localImgPath, cc.find("BackgroundMask/Background", this.node).getComponent(cc.Sprite));
                    return;
                }
                let oBgRequestParameters = {
                    "view": "json",
                    "id": strCategoryId,
                    "start": 0,
                    "limit": 1,
                    "sortField": "",
                    "sortDirection": "",
                    "appId": strAppId == "" ? "" : (strAppId || this._strAppId),
                    "token": Common.TEST_API_TOKEN
                }
                Network.ajax('GET', Common.TOPDRAW_API_SERVER + "Category/List", null, oBgRequestParameters,
                    Common.timeoutify(function (strResponse) {
                        try {
                            var oJSONResult = JSON.parse(strResponse);
                            if (oJSONResult.businessCode == "success") {
                                var strSrc = null;
                                if (oJSONResult.resultSet.length) {
                                    var val = oJSONResult.resultSet[0].images;
                                    strImageTag = strImageTag || "background";
                                    iIndex = iIndex || 0;
                                    if (val && val != '' && val != 'null') {
                                        if (val.list && val.list instanceof Array && val.list.length > 0
                                            && val.map[strImageTag] && val.map[strImageTag] instanceof Array && val.map[strImageTag].length > iIndex
                                        ) {
                                            if (val.list[val.map[strImageTag][iIndex]].fileUrl) {
                                                strSrc = val.list[val.map[strImageTag][iIndex]].fileUrl;
                                            }
                                        }
                                    }
                                    strSrc = this.getImageByTag(val, "background") || this.getImageByTag(val);
                                    if (strSrc) {
                                        Network.loadImageInNativeRuntime(
                                            strSrc
                                            , null,
                                            function (texture, iRequestId) {
                                                nodeBg.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
                                            },
                                            null,
                                            this
                                        );
                                    }
                                }
                                if (!strSrc) {
                                    Common.renderSpriteByLocalImage(localImgPath, cc.find("BackgroundMask/Background", this.node).getComponent(cc.Sprite));

                                }
                                this["RequestPageBackgroundLoaded"] = true;
                                cc.log("Business Success : Get Page Background");
                            } else {
                                cc.log("Business Error : Get Page Background..." + oJSONResult.description);
                            }
                        } catch (ex) {
                            cc.log("Business Exception : Get Page Background.." + ex);
                        }
                    }, 5, function () {
                        Common.renderSpriteByLocalImage(localImgPath, cc.find("BackgroundMask/Background", this.node).getComponent(cc.Sprite));
                    }, this, "PageBackground"),
                    function (strResponse) {
                        cc.log("Communication Error : Get Page Background..." + strResponse + "\r\n");
                    }, this, "uuid"
                );
            } catch (error) {
                if (cc.sys.isNative) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "getPageBg Error in TVCanvas==>" + error);
                }
            }

        },

        /**
         * 检查播放列表中的总个数
         * @param strAppId
         * @param iCount2Add 添加个数
         * @param fnSuccess 成功回调
         * @param fnFailure 成功回调
         * @param bDelayed 是否延迟调用  调用前可能有弹框需求
         */
        checkPlaylistCount: function (strAppId, iCount2Add, fnSuccess, fnFailure, bDelayed) {
            try {
                if (this._iPlaylistItemTotalCount == undefined || this._iPlaylistItemTotalCount == null) {
                    Network.ajax('GET', Common.TOPDRAW_API_SERVER + "User/ListPlaylistItem", null,
                        {
                            'view': 'json',
                            'start': 0,
                            'limit': 1,
                            'sortField': 'sequence',
                            'sortDirection': 'desc',
                            "appId": strAppId,
                            "token": Common.TEST_API_TOKEN
                        },
                        function (strResponse) {
                            try {
                                var oJSONResult = JSON.parse(strResponse);
                                if (oJSONResult.businessCode == "success") {
                                    this._iPlaylistItemTotalCount = oJSONResult.count;
                                    if (this._iPlaylistItemTotalCount + iCount2Add > Common.PLAY_LIST_ITEM_COUNT_LIMIT) {
                                        this.commonTip(BusinessParameter.ADD_2_PLAY_LIST_CEIL_PROMPT, Common.ADD_2_PLAY_LIST_CEIL_PROMPT_DURATION, 0, 0, bDelayed ? fnCallback : null);
                                    } else {
                                        bDelayed = false;
                                    }
                                    if (!bDelayed) {
                                        fnSuccess && fnSuccess.call(this);
                                    }
                                    cc.log("Business Success : Check Play List Item Count");
                                } else {
                                    fnFailure && fnFailure.call(this);
                                    cc.log("Business Error : Check Play List Item Count..." + oJSONResult.description);
                                }
                            } catch (ex) {
                                fnFailure && fnFailure.call(this);
                                cc.log("Business Exception : Check Play List Item Count.." + ex);
                            }
                        },
                        function (strResponse) {
                            fnFailure && fnFailure.call(this);
                            cc.log("Communication Error : Check Play List Item Count..." + strResponse + "\r\n");
                        }, this, "uuid"
                    );
                } else {
                    if (this._iPlaylistItemTotalCount + iCount2Add > Common.PLAY_LIST_ITEM_COUNT_LIMIT) {
                        this.commonTip(BusinessParameter.ADD_2_PLAY_LIST_CEIL_PROMPT, Common.ADD_2_PLAY_LIST_CEIL_PROMPT_DURATION, 0, 0, bDelayed ? fnCallback : null);
                    } else {
                        bDelayed = false;
                    }
                    if (!bDelayed) {
                        fnSuccess && fnSuccess.call(this);
                    }
                }
            } catch (error) {
                if (cc.sys.isNative) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "checkPlaylistCount Error in TVCanvas==>" + error);
                }
            }

        },

        cancelSimpleTip: function () {
            let nodeTip = cc.find("CommonTip", this.node);
            nodeTip.opacity = 0;
        },

        /**
         *黄色提示框
         * @param strTip String
         * @param iTime Number
         */
        commonSimpleTip: function (strTip, iTime, iTipX, iTipY) {
            try {
                this.commonSimpleTipFnCallback && this.unschedule(this.commonSimpleTipFnCallback);
                if (!strTip) return;
                iTime = iTime || 5;
                let labelText = null;
                let nodeTip = cc.find("CommonTip", this.node);
                let nodeText = nodeTip && nodeTip.getChildByName("TipText");
                let sprite = null;
                if (!nodeText) {
                    nodeTip = new cc.Node("CommonTip");
                    sprite = nodeTip.addComponent(cc.Sprite);
                    let strLoadImagePath = 'GameDetail/icon_window';
                    Common.renderSpriteByLocalImage(strLoadImagePath, sprite);

                    nodeTip.parent = this.node;
                    nodeTip.zIndex = 1000;
                    nodeText = new cc.Node("TipText");
                    nodeText.color = new cc.Color(246, 247, 3);
                    labelText = nodeText.addComponent(cc.Label);
                    labelText.fontSize = 28;
                    labelText.verticalAlign = cc.macro.VerticalTextAlignment.CENTER;
                    nodeTip.addChild(nodeText);
                } else {
                    labelText = nodeText.getComponent(cc.Label);
                }
                labelText.string = strTip;
                //绘制图形
                nodeTip.x = iTipX || 0;
                nodeTip.y = iTipY || 0;
                nodeTip.zIndex = cc.macro.MAX_ZINDEX;
                nodeTip.opacity = 255;
                if (!this.commonSimpleTipFnCallback) {
                    this.commonSimpleTipFnCallback = function () {
                        nodeTip.opacity = 0;
                    }
                }
                this.scheduleOnce(this.commonSimpleTipFnCallback, iTime); //修改tip时间
            } catch (error) {
                if (cc.sys.isNative) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "commonSimpleTip Error in TVCanvas==>" + error);
                }
            }

        },

        /**
         * 系统提示框
         * @param aTip
         * @param iTime
         * @param iTipX
         * @param iTipY
         * @param fnCallback
         */
        commonTip: function (aTip, iTime, iTipX, iTipY, fnCallback) {
            try {
                this.commonTipFnCallback && this.unschedule(this.commonTipFnCallback);
                this.commonTipFnCallback = null;
                if (!aTip || !aTip.length) return;
                iTime = iTime || 5;
                let nodeTip = cc.find("CommonTip", this.node);
                let nodeTextList;
                if (!nodeTip) {
                    nodeTip = new cc.Node("CommonTip");
                    nodeTextList = new cc.Node("TextList");
                    nodeTextList.parent = nodeTip;
                    nodeTip.parent = this.node;
                    nodeTip.zIndex = 1000;
                    let layoutTip = nodeTextList.addComponent(cc.Layout);
                    layoutTip.type = cc.Layout.Type.VERTICAL;
                    layoutTip.resizeMode = cc.Layout.ResizeMode.CONTAINER;
                    layoutTip.spacingY = 10;
                    let strLoadImagePath = 'Texture/simple_system_prompt_bg';
                    Common.renderSpriteByLocalImage("Texture/system_prompt_bg", nodeTip.addComponent(cc.Sprite));

                } else {
                    nodeTextList = nodeTip.getChildByName("TextList");
                    nodeTextList.removeAllChildren();
                }
                for (let i = 0; i < aTip.length; i++) {
                    let nodeTextChildren = new cc.Node("TipText" + i);
                    let labelText = nodeTextChildren.addComponent(cc.Label);
                    labelText._fontSize = 24;
                    nodeTextList.addChild(nodeTextChildren);
                    labelText.string = aTip[i];
                }

                nodeTip.x = iTipX || 0;
                nodeTip.y = iTipY || 0;
                nodeTip.opacity = 255;
                let self = this;
                this.commonTipFnCallback = function () {
                    nodeTip.opacity = 0;
                    fnCallback && fnCallback.call(self);
                }
                this.scheduleOnce(this.commonTipFnCallback, iTime); //修改tip时间
            } catch (error) {
                if (cc.sys.isNative) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "commonTip Error in TVCanvas==>" + error);
                }
            }

        },

        /**
         * 系统退出提示框
         */
        showDetainBox: function (fiBackend, bHideBg) {
            try {
                this._bShowExitBox = true;
                if (this._nodeSystemPrompt) {
                    Network.ajax("GET", Common.TOPDRAW_API_SERVER + "detain_box.json", null, null,
                        function (strResponse) {
                            try {
                                // cc.log("退出挽留页远程数据:" + strResponse);
                                var oJSONResult = JSON.parse(strResponse);
                                this._nodeSystemPrompt.opacity = 255;
                                let nodeTitle = cc.find("PromptBox/Title", this._nodeSystemPrompt);
                                let nodeDesc = cc.find("PromptBox/Content", this._nodeSystemPrompt);
                                nodeTitle.getComponent(cc.Label).string = oJSONResult.resultSet[0].name;
                                var description = oJSONResult.resultSet[0].description;
                                if (description.length > 80) {
                                    description = description.substring(0, 80) + "...";
                                }
                                nodeDesc.getComponent(cc.Label).string = description;
                                Network.loadImageInNativeRuntime(
                                    Common.TOPDRAW_IMAGE_SERVER + oJSONResult.resultSet[0].images.list[0].fileUrl, null,
                                    function (texture, iRequestId) {
                                        cc.find("PromptBox/Pic", this._nodeSystemPrompt).getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
                                    }, function () { }, this
                                );
                                if (null == this._aFocusTargets[1]) {   //focus放到第二层级,避免冲突
                                    this._aFocusTargets[1] = [];
                                }
                                cc.find("PromptBox/Look", this._nodeSystemPrompt).getComponent(FocusInfo).setTVLink(oJSONResult.resultSet[0].tvlink);
                                this._aFocusTargets[1]['system_confirm_btn'] = cc.find("PromptBox/Confirm", this._nodeSystemPrompt);
                                this._aFocusTargets[1]['system_cancel_btn'] = cc.find("PromptBox/Cancel", this._nodeSystemPrompt);
                                this._aFocusTargets[1]['system_look'] = cc.find("PromptBox/Look", this._nodeSystemPrompt);
                                this._fiBeforeDetainBox = this._fiCurrentFocus;
                                this._fiBackend = fiBackend;
                                this._iSceneStatus = 1;
                                this._cFocus.flyFocus(this._fiCurrentFocus, this._aFocusTargets[1]['system_cancel_btn'].getComponent(FocusInfo), Common.MOVE_DIRECTION_UP, this._fFocusScaleFactor, null);
                                this._bIsLoadingPfbSystemPrompt = false;
                            } catch (error) {
                                cc.log("Business Exception:Get showDetainBox..." + error);
                            }
                        },
                        function (strResponse) {
                            cc.log("Business Error:Get showDetainBox..." + strResponse);
                        }, this, "uuid");
                } else {
                    this._bIsLoadingPfbSystemPrompt = true;
                    //初始系统退出弹框
                    Common.loadRes('Prefab/pfbSystemPrompt',//提示预制
                        function (loadedResource) {
                            this._nodeSystemPrompt = cc.instantiate(loadedResource);
                            this._nodeSystemPrompt.parent = this.node;
                            if (bHideBg) {
                                this._nodeSystemPrompt.getChildByName("Background").opacity = 0;
                            }
                            let nodeConfirm = cc.find("PromptBox/Confirm", this._nodeSystemPrompt);
                            let nodeCancel = cc.find("PromptBox/Cancel", this._nodeSystemPrompt);
                            let nodeLook = cc.find("PromptBox/Look", this._nodeSystemPrompt);
                            nodeConfirm.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, 0, nodeConfirm.width, nodeConfirm.height));
                            nodeCancel.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, 0, nodeCancel.width, nodeCancel.height));
                            let fiConfirm = nodeConfirm.addComponent(FocusInfo);
                            let fiCancel = nodeCancel.addComponent(FocusInfo);
                            let fiLook = nodeLook.addComponent(FocusInfo);
                            fiConfirm.init('{"click": [{"action": "onSystemPromptCancelClick"}]}', true);
                            fiCancel.init('{"click": [{"action": "onSystemPromptConfirmClick"}]}', true);
                            fiLook.init('', true);
                            this.showDetainBox(fiBackend);
                        },
                        function (error) {
                            cc.log("Error When Loading Prefab pfbSystemPrompt ...");
                        }, this
                    );
                }
            } catch (error) {
                if (cc.sys.isNative) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "showDetainBox Error in TVCanvas==>" + error);
                }
            }

        },
        hideDetainBox: function () {
            try {
                this._nodeSystemPrompt.opacity = 0;
                delete this._aFocusTargets[1]['system_confirm_btn'];
                delete this._aFocusTargets[1]['system_cancel_btn'];
                this._iSceneStatus = 0;
                let iX = Common.SCREEN_WIDTH / 2 + Common.getX(this._fiBeforeDetainBox.node) - this._fiBeforeDetainBox.node.width / 2;
                let iY = Common.SCREEN_HEIGHT / 2 - Common.getY(this._fiBeforeDetainBox.node) + this._fiBeforeDetainBox.node.height / 2;
                cc.log("记忆焦点:" + this._fiBeforeDetainBox.node.name);
                if (this._fiBeforeDetainBox.getEnable() && iX >= 0 && iX <= Common.SCREEN_WIDTH && iY >= 0 && iY <= Common.SCREEN_HEIGHT + 50) {//这里是考虑给播放元素设置了虚拟位置
                    this._cFocus.flyFocus(this._fiCurrentFocus, this._fiBeforeDetainBox, Common.MOVE_DIRECTION_UP, this._fFocusScaleFactor, null);
                } else {
                    this._cFocus.flyFocus(this._fiCurrentFocus, this._fiBackend, Common.MOVE_DIRECTION_UP, this._fFocusScaleFactor, null);
                }
                this._bShowExitBox = false;
            } catch (error) {
                if (cc.sys.isNative) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "hideDetainBox Error in TVCanvas==>" + error);
                }
            }

        },
        /**
         * 敬请期待提示框
         */
        showComingSoonBox: function (fiBackend, bHideBg) {
            try {
                this._bShowExitBox = true;
                if (this._nodeCommonSoonPrompt) {
                    try {
                        this._nodeCommonSoonPrompt.opacity = 255;
                        if (null == this._aFocusTargets[1]) {   //focus放到第二层级,避免冲突
                            this._aFocusTargets[1] = [];
                        }
                        this._aFocusTargets[1]['coming_soon_confirm_btn'] = cc.find("PromptBox/ComingSoonConfirm", this._nodeCommonSoonPrompt);
                        this._aFocusTargets[1]['coming_soon_cancel_btn'] = cc.find("PromptBox/ComingSoonCancel", this._nodeCommonSoonPrompt);
                        this._fiBeforeDetainBox = this._fiCurrentFocus;
                        this._fiBackend = fiBackend;
                        this._iSceneStatus = 1;
                        this._cFocus.flyFocus(this._fiCurrentFocus, this._aFocusTargets[1]['coming_soon_confirm_btn'].getComponent(FocusInfo), Common.MOVE_DIRECTION_UP, this._fFocusScaleFactor, null);
                        this._bIsLoadingPfbSystemPrompt = false;
                    } catch (error) {
                        cc.log("Business Exception:Get showComingSoonBox..." + error);
                    }
                } else {
                    this._bIsLoadingPfbSystemPrompt = true;
                    //初始弹框
                    Common.loadRes('Prefab/pfbComingSoonPrompt',//提示预制
                        function (loadedResource) {
                            this._nodeCommonSoonPrompt = cc.instantiate(loadedResource);
                            this._nodeCommonSoonPrompt.parent = this.node;
                            if (bHideBg) {
                                this._nodeCommonSoonPrompt.getChildByName("Background").opacity = 0;
                            }
                            let nodeConfirm = cc.find("PromptBox/ComingSoonConfirm", this._nodeCommonSoonPrompt);
                            let nodeCancel = cc.find("PromptBox/ComingSoonCancel", this._nodeCommonSoonPrompt);
                            nodeConfirm.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, 0, nodeConfirm.width, nodeConfirm.height));
                            nodeCancel.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, 0, nodeCancel.width, nodeCancel.height));
                            let fiConfirm = nodeConfirm.addComponent(FocusInfo);
                            let fiCancel = nodeCancel.addComponent(FocusInfo);
                            fiConfirm.init('{"click": [{"action": "onComingSoonConfirmClick"}]}', true);
                            fiCancel.init('{"click": [{"action": "onComingSoonCancelClick"}]}', true);
                            this.showComingSoonBox(fiBackend);
                        },
                        function (error) {
                            cc.log("Error When Loading Prefab pfbSystemPrompt ...");
                        }, this
                    );
                }
            } catch (error) {
                if (cc.sys.isNative) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "showComingSoonBox Error in TVCanvas==>" + error);
                }
            }

        },
        hideComingSoonBox: function () {
            try {
                this._nodeCommonSoonPrompt.opacity = 0;
                delete this._aFocusTargets[1]['system_confirm_btn'];
                delete this._aFocusTargets[1]['system_cancel_btn'];
                this._iSceneStatus = 0;
                let iX = Common.SCREEN_WIDTH / 2 + Common.getX(this._fiBeforeDetainBox.node) - this._fiBeforeDetainBox.node.width / 2;
                let iY = Common.SCREEN_HEIGHT / 2 - Common.getY(this._fiBeforeDetainBox.node) + this._fiBeforeDetainBox.node.height / 2;
                cc.log("记忆焦点:" + this._fiBeforeDetainBox.node.name);
                if (this._fiBeforeDetainBox.getEnable() && iX >= 0 && iX <= Common.SCREEN_WIDTH && iY >= 0 && iY <= Common.SCREEN_HEIGHT + 50) {//这里是考虑给播放元素设置了虚拟位置
                    this._cFocus.flyFocus(this._fiCurrentFocus, this._fiBeforeDetainBox, Common.MOVE_DIRECTION_UP, this._fFocusScaleFactor, null);
                } else {
                    this._cFocus.flyFocus(this._fiCurrentFocus, this._fiBackend, Common.MOVE_DIRECTION_UP, this._fFocusScaleFactor, null);
                }
                this._bShowExitBox = false;
            } catch (error) {
                if (cc.sys.isNative) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "hideComingSoonBox Error in TVCanvas==>" + error);
                }
            }

        },
        getImageByTag: (val, strTag, index) => {
            try {
                strTag = strTag || "normal";
                index = index || 0;
                var strUrl = null;
                if (val && val != '' && val != 'null') {
                    if (val.list && val.list instanceof Array && val.list.length > 0
                        && val.map[strTag] && val.map[strTag] instanceof Array && val.map[strTag].length > 0 && !isNaN(val.map[strTag][index])
                    ) {
                        if (val.list[val.map[strTag][index]].fileUrl) {
                            strUrl = Common.TOPDRAW_IMAGE_SERVER + val.list[val.map[strTag][index]].fileUrl;
                        }
                    }
                }
                return strUrl;
            } catch (error) {
                if (cc.sys.isNative) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "getImageByTag Error in TVCanvas==>" + error);
                }
            }

        },
        onGetAuthInfo: function (iAuthCode, strAuthDescription) {
            try {
                if (iAuthCode == 10) {
                    Common.AUTH_STATUS = 2;
                }
                cc.log("onGetAuthInfo==>" + strAuthDescription);
            } catch (error) {
                if (cc.sys.isNative) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "onGetAuthInfo Error in TVCanvas==>" + error);
                }
            }

        },
        // onDestroy : function () {
        //     cc.sys.garbageCollect();
        // },
        //给每个场景的场景焦点初始化加一个通用的通知事件
        onFocusInit: function () {
            try {
                this._bIsFocusInit = true;
                if (this._strAppId != BusinessParameter.KTV_APPID && !this._strPlaylistAppId) {
                    Common.g_iPlayerPlayedTime = 0;
                }
                try {
                    //检测是否要播放bgm
                    // if(!this._ComOperation){
                    //     Common.g_iPlayerPlayedTime = 0;
                    //     let strSceneName = cc.director.getScene().name;
                    //     let iLeft=590, iTop=310, iWidth=100, iHeight=100;
                    //     if(strSceneName == "sceneRankList"){
                    //         iLeft = -590;
                    //     }
                    //     if(strSceneName == "sceneSearch"){
                    //         iLeft = -590;
                    //     }
                    //     if(strSceneName == "sceneSubjectTemplate"){
                    //         iLeft = 0;
                    //     }
                    //     this.playBGM(this._strAppId,iLeft, iTop, iWidth, iHeight);
                    // }

                    //检测loading页地址是否要更新
                    // if(cc.sys.isNative){
                    //     this.refreshLoadingBg();
                    // }
                    //做一个测试按钮用来测试重启
                    // let nodeRestartAppBtn = new cc.Node('nodeRestartAppBtn');
                    // nodeRestartAppBtn.parent = this.node;
                    // nodeRestartAppBtn.zIndex = 111;
                    // nodeRestartAppBtn.x = 529;
                    // nodeRestartAppBtn.y = 307;
                    // Common.renderSpriteByLocalImage('Texture/logo',nodeRestartAppBtn.addComponent(cc.Sprite));
                    // let compScene = this;
                    // nodeRestartAppBtn.on(cc.Node.EventType.TOUCH_START,function () {
                    //     compScene.restartApp();
                    //   if (cc.sys.isNative){
                    //       jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "checkOut4YH", "(Ljava/lang/String;)V","Pyinyue01by25");
                    //   }
                    //});
                } catch (err) {
                }
                this._cLog.screenI("GC:初始化完焦点之后执行");
                //cc.sys.garbageCollect();
                this.updateTimer = 0;
                this.updateTimer4GC = 0;
                //this.checkUpdateManifest();
            } catch (error) {
                if (cc.sys.isNative) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "onFocusInit Error in TVCanvas==>" + error);
                }
            }

        },
        refreshLoadingBg: function () {
            try {
                this._cLog.screenI("refreshLoadingBg start");
                let oBgRequestParameters = {
                    "view": "json",
                    "id": '1674',
                    "start": 0,
                    "limit": 1,
                    "sortField": "",
                    "sortDirection": "",
                    "token": Common.TEST_API_TOKEN
                }
                Network.ajax('GET', Common.TOPDRAW_API_SERVER + "Category/List", null, oBgRequestParameters,
                    function (strResponse) {
                        try {
                            var oJSONResult = JSON.parse(strResponse);
                            if (oJSONResult.businessCode == "success") {
                                this._cLog.screenI("oJSONResult.resultSet.length:" + oJSONResult.resultSet.length);
                                var strSrc = null;
                                if (oJSONResult.resultSet.length) {
                                    var val = oJSONResult.resultSet[0].images;
                                    let strImageTag = "normal";
                                    let iIndex = 0;
                                    if (val && val != '' && val != 'null') {
                                        if (val.list && val.list instanceof Array && val.list.length > 0
                                            && val.map[strImageTag] && val.map[strImageTag] instanceof Array && val.map[strImageTag].length > iIndex
                                        ) {
                                            if (val.list[val.map[strImageTag][iIndex]].fileUrl) {
                                                strSrc = val.list[val.map[strImageTag][iIndex]].fileUrl;
                                            }
                                        }
                                    }
                                    this._cLog.screenI("strSrc:" + strSrc);
                                    if (strSrc) {
                                        //这一步的目的是为背景图片设置缓存,提高下次进来的时候的显示速度
                                        Network.loadImageInNativeRuntime(
                                            Common.TOPDRAW_IMAGE_SERVER + strSrc
                                            , null,
                                            function (texture, iRequestId) {
                                                let nodeLoadingBg = new cc.Node("loadingBg");
                                                nodeLoadingBg.addComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
                                            },
                                            null,
                                            this

                                        );
                                        this._cLog.screenI("有了地址就可以开始设置参数了:");
                                        // jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "setSharedPreferences", "(Ljava/lang/String;Ljava/lang/String;)V", 'loadingImg', Common.TOPDRAW_IMAGE_SERVER + strSrc);
                                    }
                                }
                                cc.log("Business Success : Get Loading Background");
                            } else {
                                cc.log("Business Error : Get Loading Background..." + oJSONResult.description);
                            }
                        } catch (ex) {
                            cc.log("Business Exception : Get Loading Background.." + ex);
                        }
                    },
                    function (strResponse) {
                        cc.log("Communication Error : Get Loading Background..." + strResponse + "\r\n");
                    }, this, "uuid"
                );
            } catch (error) {
                if (cc.sys.isNative) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "refreshLoadingBg Error in TVCanvas==>" + error);
                }
            }

        },
        checkUpdateManifest: function () {
            //感觉每个页面都应该做热更新检测, 初始化焦点再做检测比较稳妥
            if (cc.sys.isNative) {
                this._cLog.screenI('checkUpdateManifest : ');
                let self = this;
                cc.loader.loadRes('project', function (err, manifest) {
                    self.onManifestLoaded(err, manifest)
                });
            }
        },
        onManifestLoaded: function (err, manifest) {
            this._cLog.screenI('manifest loaded : ');
            this._cLog.screenI('manifest loaded : ' + JSON.stringify(manifest));
            this._oLocalManifest = manifest;
            this._storagePath = ((jsb.fileUtils ? jsb.fileUtils.getWritablePath() : '/') + 'blackjack-remote-asset');
            this._cLog.screenI('Storage path for remote asset : ' + this._storagePath);
            this._am = new jsb.AssetsManager('', this._storagePath);
            let self = this;
            this._am.setVersionCompareHandle(function (versionA, versionB) {
                self._cLog.screenI("JS Custom Version Compare: version A is " + versionA + ', version B is ' + versionB);
                var vA = versionA.split('.');
                var vB = versionB.split('.');
                for (var i = 0; i < vA.length; ++i) {
                    var a = parseInt(vA[i]);
                    var b = parseInt(vB[i] || 0);
                    if (a === b) {
                        continue;
                    }
                    else {
                        return a - b;
                    }
                }
                if (vB.length > vA.length) {
                    return -1;
                }
                else {
                    return 0;
                }
            });
            this._am.setVerifyCallback(function (path, asset) {
                // When asset is compressed, we don't need to check its md5, because zip file have been deleted.
                var compressed = asset.compressed;
                // Retrieve the correct md5 value.
                var expectedMD5 = asset.md5;
                // asset.path is relative path and path is absolute.
                var relativePath = asset.path;
                // The size of asset file, but this value could be absent.
                var size = asset.size;
                if (compressed) {
                    self._cLog.screenI("Verification passed : " + relativePath);
                    return true;
                }
                else {
                    self._cLog.screenI("Verification passed : " + relativePath + ' (' + expectedMD5 + ')');
                    return true;
                }
            });
            if (cc.sys.os === cc.sys.OS_ANDROID) {
                // Some Android device may slow down the download process when concurrent tasks is too much.
                // The value may not be accurate, please do more test and find what's most suitable for your game.
                this._am.setMaxConcurrentTask(2);
            }
            this._cLog.screenI('checkUpdate : ');
            this._cLog.screenI('this._am.getState : ' + this._am.getState());
            if (this._am.getState() === jsb.AssetsManager.State.UNINITED) {
                // Resolve md5 url
                var url = this._oLocalManifest.nativeUrl;
                if (cc.loader.md5Pipe) {
                    url = cc.loader.md5Pipe.transformURL(url);
                }
                this._am.loadLocalManifest(url);
            }
            if (!this._am.getLocalManifest() || !this._am.getLocalManifest().isLoaded()) {
                this._cLog.screenI('Failed to load local manifest ...');
                return;
            }
            this._am.setEventCallback(this.checkCb.bind(this));
            this._cLog.screenI('checkUpdate2 : ');
            this._am.checkUpdate();
        },
        //一旦有更新,则进行热更新
        checkCb: function (event) {
            let bHotUpdate = false;
            switch (event.getEventCode()) {
                case jsb.EventAssetsManager.NEW_VERSION_FOUND:
                    bHotUpdate = true;
                    break;
                default:
                    return;
            }
            this._cLog.screenI('是否更新: ');
            if (!bHotUpdate) {
                this._am.setEventCallback(null);
                this._checkListener = null;
                this._bHotUpdateUpdating = false;
            } else {
                this.hotUpdate();
            }
        },
        updateCb: function (event) {
            var needRestart = false;
            var failed = false;
            switch (event.getEventCode()) {
                case jsb.EventAssetsManager.ERROR_NO_LOCAL_MANIFEST:
                    this._cLog.screenI('No local manifest file found, hot update skipped.');
                    failed = true;
                    break;
                case jsb.EventAssetsManager.UPDATE_PROGRESSION:
                    this._cLog.screenI('fileLabel: ' + (event.getDownloadedFiles() + ' / ' + event.getTotalFiles()));
                    this._cLog.screenI('byteLabel: ' + (event.getDownloadedBytes() + ' / ' + event.getTotalBytes()));
                    var msg = event.getMessage();
                    if (msg) {
                        this._cLog.screenI('Updated file: ' + msg);
                    }
                    break;
                case jsb.EventAssetsManager.ERROR_DOWNLOAD_MANIFEST:
                case jsb.EventAssetsManager.ERROR_PARSE_MANIFEST:
                    this._cLog.screenI('Fail to download manifest file, hot update skipped.');
                    failed = true;
                    break;
                case jsb.EventAssetsManager.ALREADY_UP_TO_DATE:
                    this._cLog.screenI('Already up to date with the latest remote version.');
                    failed = true;
                    break;
                case jsb.EventAssetsManager.UPDATE_FINISHED:
                    this._cLog.screenI('Update finished. ' + event.getMessage());
                    let strLocalPackageURL;
                    try {
                        this._cLog.screenI('Update finished. 11111');
                        let oLocalManifest = this._am.getLocalManifest();
                        this._cLog.screenI('Update finished. 22222');
                        strLocalPackageURL = oLocalManifest.getPackageUrl();
                        this._cLog.screenI('Update finished. 44444');
                    } catch (err) {
                        this._cLog.screenI('Update finished.err==> ' + err);
                    }
                    this._cLog.screenI('Update finished==> ' + strLocalPackageURL + "update");
                    //获取更新信息
                    Network.ajax("GET", strLocalPackageURL + "update.json",
                        null,
                        null,
                        function (strResponse) {
                            try {
                                this._cLog.screenI('Update finished.1==> ' + strResponse);
                                this._cLog.screenI('Update finished.2==> ' + JSON.stringify(strResponse));
                            } catch (ex) {
                                cc.log("Business Exception : Request Update Info..." + ex);
                            }
                        },
                        function (strResponse) {
                            cc.log("Communication Error : Request Update Info..." + strResponse + "\r\n");
                        }, this, "uuid"
                    );//Ajax
                    needRestart = true;
                    break;
                case jsb.EventAssetsManager.UPDATE_FAILED:
                    this._cLog.screenI('Update failed. ' + event.getMessage());
                    this._bHotUpdateUpdating = false;
                    this._bHotUpdateCanRetry = true;
                    break;
                case jsb.EventAssetsManager.ERROR_UPDATING:
                    this._cLog.screenI('Asset update error: ' + event.getAssetId() + ', ' + event.getMessage());
                    break;
                case jsb.EventAssetsManager.ERROR_DECOMPRESS:
                    this._cLog.screenI(event.getMessage());
                    break;
                default:
                    break;
            }
            if (failed) {
                this._am.setEventCallback(null);
                this._HotUpdateListener = null;
                this._bHotUpdateUpdating = false;
            }
            if (needRestart) {
                this._am.setEventCallback(null);
                this._HotUpdateListener = null;
                // Prepend the manifest's search path
                var searchPaths = jsb.fileUtils.getSearchPaths();
                var newPaths = this._am.getLocalManifest().getSearchPaths();
                Array.prototype.unshift.apply(searchPaths, newPaths);
                cc.sys.localStorage.setItem('HotUpdateSearchPaths', JSON.stringify(searchPaths));
                jsb.fileUtils.setSearchPaths(searchPaths);
                //重启
            }
        },
        hotUpdate: function () {
            if (this._am && !this._bHotUpdateUpdating) {
                this._am.setEventCallback(this.updateCb.bind(this));
                if (this._am.getState() === jsb.AssetsManager.State.UNINITED) {
                    // Resolve md5 url
                    var url = this._oLocalManifest.nativeUrl;
                    if (cc.loader.md5Pipe) {
                        url = cc.loader.md5Pipe.transformURL(url);
                    }
                    this._am.loadLocalManifest(url);
                }
                this._iHotUpdateFailCount = 0;
                this._am.update();
                this._bHotUpdateUpdating = true;
            }
        },
        //开挂的BGM
        playBGM: function (strAppId, iLeft, iTop, iWidth, iHeight) {
            try {
                this.bPlayBGM = true;
                let oPlayListRequestParameters = {
                    'view': "json",
                    'start': 0,
                    'limit': 20,
                    "appId": (this._strAppId == BusinessParameter.DOLPHINS_APPID ? "" : this._strAppId) || BusinessParameter.KTV_APPID,
                    "token": Common.TEST_API_TOKEN
                }
                Network.ajax('GET', Common.TOPDRAW_API_SERVER + "Media/List", null, oPlayListRequestParameters,
                    function (strResponse) {
                        try {
                            var oJSONResult = JSON.parse(strResponse);
                            if (oJSONResult.businessCode == "success") {
                                this._aBGMSongIds = [];
                                let oSongs = {};
                                for (let i = 0; i < oJSONResult.resultSet.length; i++) {
                                    if (!oSongs[oJSONResult.resultSet[i].id]) {
                                        oSongs[oJSONResult.resultSet[i].id] = 1;
                                        this._aBGMSongIds.push(oJSONResult.resultSet[i].id);
                                    }
                                }
                                let nodePlayCtrl = new cc.Node("PlayCtrl");
                                nodePlayCtrl.parent = this.node;
                                this._ComOperation = nodePlayCtrl.addComponent("OperateVideoPlay");
                                this._ComOperation.init(this);
                                this._iBGMSongIndex = parseInt(Math.random() * this._aBGMSongIds.length);
                                this._cLog.screenI("准备获取播放地址");
                                this.nextMedia = function () {
                                    if (this._aBGMSongIds && this._aBGMSongIds.length) {
                                        this._iBGMSongIndex = (parseInt(Math.random() * (this._aBGMSongIds.length - 1)) + this._iBGMSongIndex + 1) % this._aBGMSongIds.length;
                                        this.getPlayURLAndPlay(strAppId, iLeft, iTop, iWidth, iHeight);
                                    }
                                }
                                this.getPlayURLAndPlay(strAppId, iLeft, iTop, iWidth, iHeight);
                                cc.log("Business Success : Get Play List 4 BGM");
                            } else {
                                cc.log("Business Error : Get Play List 4 BGM..." + oJSONResult.description);
                            }
                        } catch (ex) {
                            cc.log("Business Exception : Get Play List 4 BGM.." + ex);
                        }
                    },
                    function (strResponse) {
                        cc.log("Communication Error : Get Play List 4 BGM..." + strResponse + "\r\n");
                    }, this, "uuid"
                );
            } catch (error) {
                if (cc.sys.isNative) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "playBGM Error in TVCanvas==>" + error);
                }
            }

        },
        getPlayURLAndPlay: function (strAppId, iLeft, iTop, iWidth, iHeight) {
            try {
                this._cLog.screenI("准备获取播放地址getPlayURLAndPlay");
                this._ComOperation.initPlayer(iLeft, iTop, iWidth, iHeight, false, false, true, 0, true);
                this.onGetPlayURL(Common.TEST_PLAY_URL);
                if (cc.sys.isNative) {
                    this._cLog.screenI("准备获取播放地址getPlayURLAndPlay2222");
                    // let o1 = jsb.reflection.callStaticMethod("com/topdraw/melody/TopdrawSDKWrapper", "getPlayURL", "(ILjava/lang/String;Ljava/lang/String;)V", parseInt(this._aBGMSongIds[this._iBGMSongIndex]), strAppId || this._strAppId || BusinessParameter.KTV_APPID, "onGetPlayURL");
                }
            } catch (error) {
                if (cc.sys.isNative) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "getPlayURLAndPlay Error in TVCanvas==>" + error);
                }
            }

        },
        onGetPlayURLFailed: function (strCode) {
            try {
                this._ComOperation.bHasVideo2Play = false;
                if (strCode && strCode == "401") {
                    this.commonSimpleTip('权限过期,即将为您重启应用!', 3);
                } else if (!this.bPlayBGM && !this._ComOperation.bHidden) {
                    this.commonSimpleTip('该节目已下线!', 3);
                }
                //this.nextMedia&&this.nextMedia();
            } catch (error) {
                if (cc.sys.isNative) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "onGetPlayURLFailed Error in TVCanvas==>" + error);
                }
            }

        },
        restartApp: function () {
            return;//这里暂时先不重启
            //上下文
            this._cLog.screenI("准备重启机顶盒");
            let compApplication = cc.find('application').getComponent(Application);
            let aSceneContext = compApplication.getSceneContext();
            let strSceneName = cc.director.getScene().name;
            this._oSceneContext.focusPath = this._fiCurrentFocus && Common.getNodePath(this._fiCurrentFocus.node);
            aSceneContext.push(this._oSceneContext);
            let aSceneParameter = compApplication.getSceneParameter();
            //针对首个进入场景无参数
            if (!aSceneParameter.length) {
                aSceneParameter.push({ 'sceneName': '' + cc.director.getScene().name });
            }
            this.commonSimpleTip('权限过期,即将为您重启应用!', 3);
            this.scheduleOnce(function () {
                this._cLog.screenI("重启咯");
                if (cc.sys.isNative) {
                    // jsb.reflection.callStaticMethod("com/topdraw/melody/MelodyApplication", "restartApp", "(Ljava/lang/String;Ljava/lang/String;)V", JSON.stringify(aSceneContext), JSON.stringify(aSceneParameter));
                }
            }, 4);
        },
        update: function (dt) {
            try {
                this.updateTimer += dt;
                this.updateTimer4GC += dt;
                if (this.updateTimer < this.updateInterval) {
                    return; // we don't need to do the math every frame
                }
                if (this.updateTimer4GC >= this.updateInterval4GC) {
                    this.updateTimer4GC = 0;
                    //this._cLog.screenI("GC:不做任何按键操作20秒之后执行");
                    //cc.sys.garbageCollect();
                }
                this.updateTimer = 0;

            } catch (err) {
                if (cc.sys.isNative) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "update Error in TVCanvas==>" + error);
                }
            }
        }
    });