VideoPlayer.js 38.9 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
//综艺唱-看 全屏播放器
var Common = require('Common');
var BusinessParameter = require('BusinessParameter');
var Network = require('Network');
var TVFocus = require('TVFocus');
var FocusInfo = require('FocusInfo');
var TVCanvas = require('TVCanvas');
var Application = require('Application');
// require("MediaPlayer");
cc.Class({
    extends: TVCanvas,

    properties: {
        LastButton: cc.Node,
        NextButton: cc.Node,
        RepeatButton: cc.Node,
        OrderButton: cc.Node,
    },
    onLoad: function () {
        try {
            this._super();
            this._iFocusStatus = 0;
            //播放器相关
            this._ComOperation = cc.find("PlayCtrl", this.node).getComponent("OperateVideoPlay");
            this._ComOperation.init(this, this.updateProgress);


            //日志相关
            // this._cLog.node.opacity = Common.DEBUG_MODE * 255;
            //this._cLog.node.opacity = 255;
            this._cLog.screenI("2222");
            this._cLog.screenI(cc.director.getScene().name + " ==> Version 1.0.2.21" + "\r\n");

            this._nodeInitFocusPath = "VideoArea/PlayPanel/Operation/Play";


            //----上下文及参数相关处理开始
            let aSceneContext = this._cApplication.getSceneContext();
            let aSceneParameter = this._cApplication.getSceneParameter();
            //参数
            this._oDefaultBackASceneParameter = {};
            cc.log(aSceneParameter);

            //上下文
            cc.log(aSceneContext);
            //播放器先不考虑焦点记忆
            if (this._cApplication.getBackStatus()) {
                let oSceneContext = aSceneContext.pop();
                if (oSceneContext) {

                }
                this._cApplication.setBackStatus(false);
                cc.log(oSceneContext);
            }

            //进度条
            let nodeProgress = cc.find("VideoArea/PlayPanel/Progress", this.node);
            let nodeProgressBase = cc.find("ProgressBase", nodeProgress);
            let nodeProgressBtn = cc.find("ProgressBtn", nodeProgressBase);
            this._iProgressWidth = nodeProgress.width;
            var fiProgressBtn = nodeProgressBtn.addComponent(FocusInfo);
            fiProgressBtn.init("", true);
            this._aFocusTargets[0]['progress_btn'] = nodeProgressBtn;
            //播放操作按钮
            let oBtnLink = {
                "Play": '{"click": [{"action": "PlayMedia"}]}',
                /*"Origin" : '{"click": [{"action": "SwitchCompanyMode"}]}',*/
                "ButtonRepeat": '{"click": [{"action": "RepeatMedia"}]}',
                "ButtonLast": '{"click": [{"action": "CutMedia"}]}',
                "ButtonNext": '{"click": [{"action": "CutMedia"}]}',
                "ButtonOrder": '{"click": [{"action": "CollectMedia"}]}',
            }
            let nodeOperation = cc.find("VideoArea/PlayPanel/Operation", this.node);
            let aOperationChildren = cc.find("Group", nodeOperation).children;
            this._aFocusTargets[1] = {};
            for (let i = 0; i < aOperationChildren.length; i++) {
                if (oBtnLink[aOperationChildren[i].name]) {
                    let fiNode = aOperationChildren[i].addComponent(FocusInfo);
                    fiNode.init(oBtnLink[aOperationChildren[i].name], true);
                    // fiNode.ignoreZIndex(true);
                    // fiNode.setFlyDelayTime(50);
                    this._aFocusTargets[1][aOperationChildren[i].name.toLowerCase()] = aOperationChildren[i];
                }
            }

            //单独设置play按钮
            let nodePlay = cc.find("Play", nodeOperation);
            // nodePlay.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, 64, 64, 64));  //没改动
            let fiNodePlay = nodePlay.addComponent(FocusInfo);
            fiNodePlay.init(oBtnLink[nodePlay.name], true);
            //nodePlay._fY = nodePlay.y -40;
            this._aFocusTargets[0][nodePlay.name.toLowerCase()] = nodePlay;

            //Nothing 当页面没有焦点元素的时候,就酱紫用个nothing处理
            var nodeNothing = cc.find("Nothing", this.node);
            var fiNothing = nodeNothing.addComponent(FocusInfo);
            fiNothing.init("", true);
            this._aFocusTargets[0]['nothing'] = nodeNothing;

            this.onCheckQueryNewTV();       //测试      :直接播放
            this.checkDataReadyAndInitFocus();

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

    checkDataReadyAndInitFocus: function () {
        try {
            if (!this._bIsFocusInit) {
                this.initFocus();
                this._bIsFocusInit = true;
            }
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "checkDataReadyAndInitFocus Error in VarietyVideo==>" + error);
            }
        }

    },
    initFocus: function () {
        try {
            this.LastButton.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, 0, this.LastButton.width, this.LastButton.height));
            this.NextButton.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, 0, this.NextButton.width, this.NextButton.height));
            this.OrderButton.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, 0, this.OrderButton.width, this.OrderButton.height));
            this.RepeatButton.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, 0, this.RepeatButton.width, this.RepeatButton.height));

            var nodeFocus = new cc.Node('nodeFocus');
            this.node.addChild(nodeFocus, 10);
            this._cFocus = this.node.getChildByName('nodeFocus').addComponent(TVFocus);
            var nodeInitFocus = cc.find(this._nodeInitFocusPath, this.node);

            this._cFocus.init('focusContainer', this,
                nodeInitFocus.getComponent(FocusInfo),
                Common.SCREEN_WIDTH, Common.SCREEN_HEIGHT, 10, 6,
                1.0, true
            );

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

    },

    onKeyDown: function (event) {
        try {
            this._super(event);
            var fiFocusTarget = null;
            var fiCurrentFocus = this._fiCurrentFocus;
            var oScrollParameter = null;

            let nodeFrom = null;
            let nodeTo = null;
            if (this._bIsFocusInit) {
                if (event.keyCode == cc.macro.KEY.up || event.keyCode == Common.ANDROID_KEY.up) {
                    if (this._fiCurrentFocus.node.name == "Nothing") {
                        fiFocusTarget = null;
                    } else {
                        fiFocusTarget = this._cFocus.findTarget(this._fiCurrentFocus, this._aFocusTargets, this._iFocusStatus, Common.MOVE_DIRECTION_UP);
                    }
                    fiFocusTarget = this.checkFocusTarget(fiFocusTarget);
                    this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Common.MOVE_DIRECTION_UP, 1.0, oScrollParameter);
                }
                if (event.keyCode == cc.macro.KEY.right || event.keyCode == Common.ANDROID_KEY.right) {
                    if (this._fiCurrentFocus.node.name == "Nothing") {
                        this._strOperationBtnPath = "VideoArea/PlayPanel/Progress/ProgressBase/ProgressBtn";
                        this._ComOperation.step(1);
                    } else if (this._fiCurrentFocus.node.name == "ProgressBtn" || this._fiCurrentFocus.node.name == "Play") {
                        this.fastForwardOnce();
                    } else {
                        fiFocusTarget = this._cFocus.findTarget(this._fiCurrentFocus, this._aFocusTargets, this._iFocusStatus, Common.MOVE_DIRECTION_RIGHT);
                    }
                    fiFocusTarget = this.checkFocusTarget(fiFocusTarget);
                    this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Common.MOVE_DIRECTION_RIGHT, 1.0, oScrollParameter);
                }
                if (event.keyCode == cc.macro.KEY.down || event.keyCode == Common.ANDROID_KEY.down) {
                    cc.log("是否显示:" + this._bShowProgress);
                    if (this._fiCurrentFocus.node.name == "Nothing") {
                        this._strOperationBtnPath = this._bMediaFree ? "VideoArea/PlayPanel/Operation/Play" : "VideoArea/PlayPanel/Operation/Group/Collect";
                        this.showOperationBtns();
                    }
                     else if (this._fiCurrentFocus.node.parent.name == "Operation" || this._fiCurrentFocus.node.parent.parent.name == "Operation") {
                        //这里说什么要做抖动
                        fiFocusTarget = this._cFocus.findTarget(this._fiCurrentFocus, this._aFocusTargets, this._iFocusStatus, Common.MOVE_DIRECTION_DOWN);
                        fiFocusTarget = this.checkFocusTarget(fiFocusTarget);
                        this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Common.MOVE_DIRECTION_DOWN, 1.0, oScrollParameter);
                    } 
                    else {
                        fiFocusTarget = this._cFocus.findTarget(this._fiCurrentFocus, this._aFocusTargets, this._iFocusStatus, Common.MOVE_DIRECTION_DOWN);
                        fiFocusTarget = this.checkFocusTarget(fiFocusTarget);
                        // if (!this._bMediaFree && this._fiCurrentFocus.node.name == "ProgressBtn") {
                        //     fiFocusTarget = cc.find("VideoArea/PlayPanel/Operation/Group/Collect", this.node).getComponent(FocusInfo);
                        // }
                        cc.log("向下滑动:"+fiFocusTarget.node.name);
                        this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Common.MOVE_DIRECTION_DOWN, 1.0, oScrollParameter);
                    }
                    if (this._fiCurrentFocus.node.name == "Play" && this._bShowProgress) {
                        this.showSelectGatherArea();
                        return;
                    }
                }
                if (event.keyCode == cc.macro.KEY.left || event.keyCode == Common.ANDROID_KEY.left) {
                    if (this._fiCurrentFocus.node.name == "Nothing") {
                        this._strOperationBtnPath = "VideoArea/PlayPanel/Progress/ProgressBase/ProgressBtn";
                        this._ComOperation.step(-1);
                    } else if (this._fiCurrentFocus.node.name == "ProgressBtn" || this._fiCurrentFocus.node.name == "Play") {
                        this.fastBackwardOnce();
                    } else {
                        fiFocusTarget = this._cFocus.findTarget(this._fiCurrentFocus, this._aFocusTargets, this._iFocusStatus, Common.MOVE_DIRECTION_LEFT);
                        fiFocusTarget = this.checkFocusTarget(fiFocusTarget);
                        this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Common.MOVE_DIRECTION_LEFT, 1.0, oScrollParameter);
                    }
                }
                if (event.keyCode == cc.macro.KEY.enter || event.keyCode == Common.ANDROID_KEY.enter || event.keyCode == cc.macro.KEY.space) {
                    this._cLog.screenI("cc.macro.KEY.enter");
                    if (this._fiCurrentFocus.node.name == "Nothing") {
                        this._strOperationBtnPath = "VideoArea/PlayPanel/Operation/Play";
                        this.playOrPause();
                    }
                    this._cLog.screenI("cc.macro.KEY.enter" + Common.TV_LINK_ACTION_CLICK);
                    this.doCurrentFocusTVLinkAction(Common.TV_LINK_ACTION_CLICK);

                }
            }
            if (event.keyCode == cc.macro.KEY.backspace || event.keyCode == Common.ANDROID_KEY.back) {
                this.backAScene();
            }
            if (!this._bShowGather) //不显示选集区域的情况下才显示进度条
                this.showProgressBarArea();
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "onKeyDown Error in VarietyVideo==>" + error);
            }
        }

    },
    fastForwardOnce: function () {
        try {
            if (this._ComOperation.now > 1 && this._ComOperation.duration && this._ComOperation.bReady2Play) {
                if (!this._bFakeProgressStart) {
                    this._bFakeProgressStart = true;
                    this._ComOperation.step(1);
                    this.schedule(this.fakeStepForward, 0.1);
                }
            }
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "fastForwardOnce Error in VarietyVideo==>" + error);
            }
        }


    },
    fastBackwardOnce: function () {
        try {
            if (this._ComOperation.now > 1 && this._ComOperation.duration && this._ComOperation.bReady2Play) {
                if (!this._bFakeProgressStart) {
                    this._bFakeProgressStart = true;
                    this._ComOperation.step(-1);
                    this.schedule(this.fakeStepBackward, 0.1);
                }
            }
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "fastBackwardOnce Error in VarietyVideo==>" + error);
            }
        }


    },
    fakeStepForward: function () {
        try {
            this._iFakeProgressStep = this._iFakeProgressStep * 2 || 2;
            let iMaxValue = parseInt(this._ComOperation.duration / 4 / 60) * 10 || 10;
            this._iFakeProgressStep = Math.min(this._iFakeProgressStep, iMaxValue);
            this._ComOperation.step(1, this._iFakeProgressStep, true);
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "fakeStepForward Error in VarietyVideo==>" + error);
            }
        }

    },
    fakeStepBackward: function () {
        try {
            this._iFakeProgressStep = this._iFakeProgressStep * 2 || 2;
            let iMaxValue = parseInt(this._ComOperation.duration / 4 / 60) * 10 || 10;
            this._iFakeProgressStep = Math.min(this._iFakeProgressStep, iMaxValue);
            this._ComOperation.step(-1, this._iFakeProgressStep, true);
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "fakeStepBackward Error in VarietyVideo==>" + error);
            }
        }

    },
    checkFocusTarget: function (fiFocusTarget) {
        try {
            if (!fiFocusTarget) {
                return null;
            }
            if (0 == fiFocusTarget.node.name.indexOf('ProgressBtn')) {
                return fiFocusTarget;
            }
            if (fiFocusTarget) {
                let fiTarget = fiFocusTarget.getComponent(FocusInfo);
                let fTargetLeft = fiTarget.getLeft();
                let fTargetTop = fiTarget.getTop();
                if (fTargetLeft <= 0 || fTargetLeft >= Common.SCREEN_WIDTH || fTargetTop >= Common.SCREEN_HEIGHT || fTargetTop <= 0) { //如果目标在限制区域内
                    fiFocusTarget = null;
                }
            }
            return fiFocusTarget;
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "checkFocusTarget Error in VarietyVideo==>" + error);
            }
        }

    },
    onBeforeFocusChange: function (event) {
        try {
            let fiFrom = event.detail.from;
            let fiTo = event.detail.to;



            if (0 == fiFrom.node.parent.name.indexOf('Operation')
                //||0 == fiFrom.node.parent.parent.name.indexOf('Operation')
                || fiFrom.node.name == "ProgressBtn"
                || fiFrom.node.name == "Choosed"
                || fiFrom.node.name == "Icon"
                || fiFrom.node.name == "Confirm"
                || fiFrom.node.name == "Cancel"
            ) {
                this.renderRect(fiFrom.node, [0, 2]);
            }

            if (0 == fiFrom.node.name.indexOf('ProgressBtn')) {
                // this._cFocus.show();
                fiFrom.node.getChildByName("Time").opacity = 0;
                fiFrom.node.getChildByName("Direction").opacity = 0;
            }

            if (0 == fiFrom.node.parent.name.indexOf('Operation')
                || 0 == fiFrom.node.parent.parent.name.indexOf('Operation')) {
                //this.node.getChildByName("OperationFocus").opacity = 0;
                // this._cFocus.show();
            }

            // if (0 == fiFrom.node.name.indexOf('Play')) {
            //     fiFrom.node.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, 0, fiFrom.node.width, fiFrom.node.height));
            // }

            // if (0 == fiFrom.node.name.indexOf('Button')) {
            //     fiFrom.node.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, 0, fiFrom.node.width, fiFrom.node.height));
            // }

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

    },
    onAfterFocusChange: function (event) {
        try {
            let fiFrom = event.detail.from;
            let fiTo = event.detail.to;

            if (0 == fiTo.node.parent.name.indexOf('Operation')
                //||0 == fiTo.node.parent.parent.name.indexOf('Operation')
                || fiTo.node.name == "ProgressBtn"
                || fiTo.node.name == "Choosed"
                || fiTo.node.name == "Icon"
                || fiTo.node.name == "Confirm"
                || fiTo.node.name == "Cancel"
            ) {
                this.renderRect(fiTo.node, [1, 3]);

            }

            if (0 == fiTo.node.name.indexOf('ProgressBtn')) {
                // this._cFocus.hide();
                fiTo.node.getChildByName("Time").opacity = 0;
                fiTo.node.getChildByName("Direction").opacity = 255;
            }

            // if (0 == fiTo.node.name.indexOf('Play')) {
            //     fiTo.node.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
            // }

            // if (0 == fiTo.node.name.indexOf('Button')) {
            //     fiTo.node.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
            // }

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

    },
    updateProgressBtnFocus: function (delta) {
        try {
            if (this._fiCurrentFocus && this._fiCurrentFocus.node.name == 'ProgressBtn') {
                this._cFocus.fly(this._fiCurrentFocus.getLeft() + delta, this._fiCurrentFocus.getTop(), this._fiCurrentFocus.getWidth(), this._fiCurrentFocus.getHeight(), Common.FOCUS_FLY_DURATION, 1.0);
            }
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "updateProgressBtnFocus Error in VarietyVideo==>" + error);
            }
        }

    },

    renderRect: function (node, aIndex) {
        try {
            let self = this;
            let compRect = node.getComponent("ccRect");
            let nodeName = node.name;
            let index = aIndex[0];
            if (nodeName == "Play") {
                let playImgSrc = "VideoPlayer/pause";
                this._ComOperation.isPlaying() ? playImgSrc = "VideoPlayer/pause" : playImgSrc = "VideoPlayer/play";
                if (this.playStatusSrc != playImgSrc) {
                    cc.loader.loadRes(playImgSrc, function (err, texture) {
                        if (!err && texture) {
                            self.playStatusSrc = playImgSrc;
                            compRect && compRect.setRenderTexture(texture);
                            compRect && compRect.setRenderRect(index);
                        }

                    });
                } else {
                    compRect && compRect.setRenderRect(index);
                }
            } else {
                if (nodeName == "Collect") {
                    this._aPlayList[this._iRequestMediaIndex] && this._aPlayList[this._iRequestMediaIndex].collected ? index = aIndex[1] : index = aIndex[0];
                }
                compRect && compRect.setRenderRect(index);
            }
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "renderRect Error in VarietyVideo==>" + error);
            }
        }

    },

    checkBtnName: function (nodeName) {
        try {
            if (nodeName == "Play") {
                this._ComOperation.isPlaying() ? nodeName = "pause" : nodeName = "play";
            }
            if (nodeName == "Origin") {
                this._bCompany ? nodeName = "origin" : nodeName = "origin1";
            }
            if (nodeName == "Collect") {
                nodeName = this._aPlayList[this._iRequestMediaIndex] && this._aPlayList[this._iRequestMediaIndex].collected ? "collected" : "collect";
            }
            let strPicName = nodeName.replace(/(.)/, function () {
                return arguments[0].toLowerCase();
            });
            return strPicName;
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "checkBtnName Error in VarietyVideo==>" + error);
            }
        }

    },

    /**
     * 从播放地址中拿fileCode去未来SDK鉴权,成功则直接播放,失败则调用checkQueryFail
     */
    onCheckQueryNewTV: function (options) {
        try {
            cc.log("onCheckQueryNewTV start...");
            this._cLog.screenI("SubIndex拿到播放播放地址" + options);
            // jsb.reflection.callStaticMethod("com/topdraw/melody/TopdrawSDKWrapper", "checkQueryNewTV", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", options, "onGetPlayURL", "checkQueryFail");

            this._ComOperation.initPlayer(0, 0, Common.SCREEN_WIDTH, Common.SCREEN_HEIGHT, true, true);     //测试
            let options = {};
            options.playurl = "http://vjs.zencdn.net/v/oceans.mp4";
            this._ComOperation.setURL(options);     //测试播放地址
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "onCheckQueryNewTV Error in SubIndex==>" + error);
            }
        }
    },

    checkQueryFail: function () {
        this._cLog.screenI("未来鉴权失败,该视频不能播放!");
        this.commonSimpleTip('该节目已下线!', 3);
        this.nextMedia();
    },

    getCollectionInfo: function () {
        try {
            if (!this._strRequestMediaId) {
                return;
            }
            /*获取收藏*/
            var oAdditionalInfoParameters = {
                "view": "json",
                "mediaIds": this._strRequestMediaId,
                "needCollection": "1",
                "start": 0,
                "limit": 1,
                "appId": this._strAppId,
                "token": Common.TEST_API_TOKEN
            }
            Network.ajax('GET', Common.TOPDRAW_API_SERVER + 'User/ListMediaAdditional', null, oAdditionalInfoParameters,
                function (strResponse) {
                    try {
                        var oJSONResult = JSON.parse(strResponse);
                        if (oJSONResult.businessCode == "success") {
                            var aCollectedMedias = oJSONResult.resultSet[0].collections;
                            let iStatus = 0;
                            if (aCollectedMedias.length && this._strRequestMediaId == aCollectedMedias[0].media_id) {
                                iStatus = 1;
                            }
                            this._aPlayList[this._iRequestMediaIndex].collected = iStatus;
                            if (this._fiCurrentFocus.node.name == "Collect") {
                                this.renderRect(cc.find("VideoArea/PlayPanel/Operation/Group/Collect", this.node), [1, 3]);
                            } else {
                                this.renderRect(cc.find("VideoArea/PlayPanel/Operation/Group/Collect", this.node), [0, 2]);
                            }
                            cc.log("Business Success : Get Collection Info Information");
                        } else {
                            cc.log("Business Error : Get Collection Info Information..." + oJSONResult.description);
                        }
                    } catch (ex) {
                        cc.log("Business Exception : Get Collection Info Information.." + ex);
                    }
                },
                function (strResponse) {
                    cc.log("Communication Error : Get Collection Info Information..." + strResponse + "\r\n");
                }, this, "uuid"
            );
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "getCollectionInfo Error in VarietyVideo==>" + error);
            }
        }

    },
    collectMedia: function () {
        try {
            if (null != this._aPlayList[this._iRequestMediaIndex].collected && this._strCollectionDefaultId != "") {
                var oCollectionRequestParameters = {
                    "view": "json",
                    "mediaId": this._strRequestMediaId,
                    "collectionId": this._strCollectionDefaultId,
                    "appId": this._strAppId,
                    "token": Common.TEST_API_TOKEN
                }
                let flag = this._aPlayList[this._iRequestMediaIndex].collected;
                //添加收藏+取消收藏
                Network.ajax('GET', Common.TOPDRAW_API_SERVER + (!flag ? "User/AddMedia2Collection" : "User/RemoveMediaFromCollection"), null, oCollectionRequestParameters,
                    function (strResponse) {
                        try {
                            var oJSONResult = JSON.parse(strResponse);
                            if (oJSONResult.businessCode == "success") {
                                this._aPlayList[this._iRequestMediaIndex].collected = flag ? 0 : 1;
                                if (this._fiCurrentFocus.node.name == "Collect") {
                                    this.renderRect(cc.find("VideoArea/PlayPanel/Operation/Group/Collect", this.node), [1, 3]);
                                } else {
                                    this.renderRect(cc.find("VideoArea/PlayPanel/Operation/Group/Collect", this.node), [0, 2]);
                                }

                                this.showOperationPrompt(!flag ? "收藏成功" : "取消收藏");
                                cc.log("Business Success : Add 2 Collection:" + !flag);
                            } else {
                                cc.log("Business Error : Add 2 Collection:" + !flag + "..." + oJSONResult.description);
                            }
                        } catch (ex) {
                            cc.log("Business Exception : Add 2 Collection:" + !flag + "..." + ex);
                        }
                    },
                    function (strResponse) {
                        cc.log("Communication Error : Add 2 Collection" + !flag + "..." + strResponse + "\r\n");
                    }, this, {
                        code: this._aPlayList[this._iRequestMediaIndex].code
                    }
                );
            }
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "collectMedia Error in VarietyVideo==>" + error);
            }
        }

    },
    nextMedia: function () {
        try {
            // if(this._bCuttingNextMedia){
            //     return;
            // }
            //this._bCuttingNextMedia = true;
            if (!this._bMediaFree) {
                //播放完一首第一首变成最后一首 下一首直接变成第一首
                var oFirst = this._aPlayList.shift();
                this._aPlayList.splice(this._aPlayList.length - 1, 0, oFirst);
                this.rankMedia(oFirst.id, this._aPlayList.length - 2);


                this._strRequestMediaId = this._aPlayList[0].id;
                this.renderPlayList();
                //歌曲要置顶
                this.rankMedia(this._strRequestMediaId, 0);
                this._ComOperation.end();
                this.getPlayURLAndPlay();
            } else {
                this.backAScene();
            }
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "nextMedia Error in VarietyVideo==>" + error);
            }
        }


    },

    checkNextMedia: function () {
        try {
            //let nodeCut = cc.find("VideoArea/PlayPanel/Operation/Group/Cut",this.node);
            if (this._iRequestMediaIndex == this._aPlayList.length - 1) {
                if (this._fiCurrentFocus.node.name == "Cut") {
                    this._cFocus.flyFocus(this._fiCurrentFocus, cc.find("VideoArea/PlayPanel/Operation/Group/Repeat", this.node).getComponent(FocusInfo), Common.MOVE_DIRECTION_LEFT, 1.0, null);
                }
                //nodeCut.active = false;
                //nodeCut.getComponent(FocusInfo).setEnable(false);
                cc.find("SongNames/NextName", this.node).opacity = 0;

            } else {
                //nodeCut.active = true;
            }
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "checkNextMedia Error in VarietyVideo==>" + error);
            }
        }

    },

    playOrPause: function () {
        try {
            var self = this;
            if (!this._ComOperation.duration) {
                return;
            }
            //测试一下播放器
            let flag = !this._ComOperation.isPlaying();
            cc.log(flag);
            this._ComOperation[flag ? "play" : "pause"]();
            if (!flag) {
                cc.loader.loadRes("VideoPlayer/pause", cc.Texture2D, function (err, texture) {
                    // cc.find("VideoArea/PlayPanel/Operation/Play", self.node).getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 64, 64, 64));
                    cc.find("VideoArea/PlayPanel/Operation/Play", self.node).getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
                });
            } else {
                cc.loader.loadRes("VideoPlayer/play", cc.Texture2D, function (err, texture) {
                    // cc.find("VideoArea/PlayPanel/Operation/Play", self.node).getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 64, 64, 64));
                    cc.find("VideoArea/PlayPanel/Operation/Play", self.node).getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
                });
            }
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "playOrPause Error in VarietyVideo==>" + error);
            }
        }

    },
    doCurrentFocusTVLinkAction: function (strAction) {

        try {
            let strTVLink = this._fiCurrentFocus.getTVLink();
            var joTVLink = null;
            joTVLink = JSON.parse(strTVLink);
            let jaOperationList = joTVLink.click;
            for (let i = 0; i < jaOperationList.length; i++) {
                switch (jaOperationList[i].action) {
                    case "PlayMedia":
                        if (!this._ComOperation.bReady2Play) {
                            return;
                        }
                        this.playOrPause();
                        break;
                    case "RepeatMedia":
                        if (this._ComOperation.bReady2Play) {
                            this._ComOperation.end();
                            this.getPlayURLAndPlay();
                        }
                        break;
                    case "CutMedia":
                        if ((!this._iScrollGroupStatus/*&&this._ComOperation.duration*/ && this._ComOperation.bReady2Play) || !cc.sys.isNative) {
                            this.nextMedia();
                        }
                        break;
                    case "CollectMedia":
                        this.collectMedia();
                        break;
                    default:
                        this.doTVLinkAction(jaOperationList[i]);
                        break;
                }
            }

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

        }
    },
    /**
     * 用于合并对象
     * @param target
     * @param firstSource
     * @returns {any}
     */
    assign: function (target, firstSource) {
        if (target === undefined || target === null)
            throw new TypeError("Cannot convert first argument to object");
        var to = Object(target);
        for (var i = 1; i < arguments.length; i++) {
            var nextSource = arguments[i];
            if (nextSource === undefined || nextSource === null) continue;
            var keysArray = Object.keys(Object(nextSource));
            for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) {
                var nextKey = keysArray[nextIndex];
                var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
                if (desc !== undefined && desc.enumerable) to[nextKey] = nextSource[nextKey];
            }
        }
        return to;
    },
    updateProgress: function (now) {
        try {
            if (this._ComOperation.duration) {
                this._cLog.screenI("更新进度条:" + now);
                if (this._ComOperation.duration == -100) {      //解决.快进到下一个节目时,播放前贴广告显示进度条       fix jerry
                    cc.find("SongNames", this.node).opacity = 0;
                }
                // if(!this._iScrollGroupStatus&&this._bCuttingNextMedia){
                //     this._bCuttingNextMedia = false;
                // }
                // if (this._ComOperation.isPlaying()) {
                //     this.checkSubscribe();
                // }
                let nodePlay = cc.find("VideoArea/PlayPanel/Operation/Play", this.node);
                // if (this._fiCurrentFocus && this._fiCurrentFocus.node.name == "Play") {
                //     this.renderRect(nodePlay, [1]);
                // } else {
                //     this.renderRect(nodePlay, [0]);
                // }
                let nodeProgress = cc.find("VideoArea/PlayPanel/Progress", this.node);
                let nodeProgressBase = cc.find("ProgressBase", nodeProgress);
                let nodeProgressBtn = cc.find("ProgressBtn", nodeProgressBase);
                cc.find("Time/Value", nodeProgressBtn).getComponent(cc.Label).string = now;
                let iDelta = nodeProgressBase.width;
                nodeProgressBase.width = nodeProgressBase.parent.width * this._ComOperation.now / this._ComOperation.duration;
                if (this._fiCurrentFocus && this._fiCurrentFocus.node.name == 'ProgressBtn') {
                    iDelta = nodeProgressBase.width - iDelta;
                    this.updateProgressBtnFocus(iDelta);
                }
            }
        } catch (error) {
            // if (cc.sys.isNative){
            //     jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V","updateProgress Error in VarietyVideo==>"+error);
            // }
        }

    },

    //显示进度条区域
    showProgressBarArea: function () {
        this.hideSelectGatherArea();
        this._cFocus.show();
        this._bShowProgress = true;
        this.unschedule(this.hideProgressBarArea);
        cc.find("VideoArea/PlayPanel/Operation/Play", this.node).active = true;
        cc.find("VideoArea/PlayPanel/Progress", this.node).active = true;
        cc.find("VideoArea/PlayPanel/Time", this.node).active = true;
        cc.find("SelectDown", this.node).active = true;
        this._iFocusStatus = 0;
        this._cFocus.flyFocus(this._fiCurrentFocus, cc.find("VideoArea/PlayPanel/Operation/Play", this.node).getComponent(FocusInfo), Common.MOVE_DIRECTION_UP, 1.0, null);
        this.scheduleOnce(this.hideProgressBarArea, 5);
    },

    hideProgressBarArea: function () {
        this._cFocus.hide();
        this._bShowProgress = false;
        this.unschedule(this.hideProgressBarArea);
        cc.find("VideoArea/PlayPanel/Operation/Play", this.node).active = false;
        cc.find("VideoArea/PlayPanel/Progress", this.node).active = false;
        cc.find("VideoArea/PlayPanel/Time", this.node).active = false;
        cc.find("SelectDown", this.node).active = false;
    },

    //显示选集区域
    showSelectGatherArea: function () {
        this.hideProgressBarArea();  //先隐藏进度条区域
        this._cFocus.show();
        this._bShowGather = true;
        this.unschedule(this.hideSelectGatherArea);
        cc.find("VideoArea/PlayPanel/Operation/Group", this.node).active = true;
        this._iFocusStatus = 1;
        this._cFocus.flyFocus(this._fiCurrentFocus, cc.find("VideoArea/PlayPanel/Operation/Group/ButtonNext", this.node).getComponent(FocusInfo), Common.MOVE_DIRECTION_UP, 1.0, null);
        this.scheduleOnce(this.hideSelectGatherArea, 5);
    },

    hideSelectGatherArea: function () {
        this._cFocus.hide();
        this._bShowGather = false;
        this.unschedule(this.hideSelectGatherArea);
        cc.find("VideoArea/PlayPanel/Operation/Group", this.node).active = false;
    },

});