OperateVideoPlay.js 38.4 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
var Common = require('Common');
var BusinessParameter = require('BusinessParameter');
var CCMediaPlayer = require('CCMediaPlayer');
cc.Class({
    extends: cc.Component,

    properties: {
        videoPlayer1: {
            default: null,
            type: cc.VideoPlayer,
        },
        currentTime: {
            default: null,
            type: cc.Label
        },
        totalTime: {
            default: null,
            type: cc.Label
        },
        loadingIcon: {
            default: null,
            type: cc.Node
        },
        now: 0,
        duration: 0,
        oScene: null,
        url: "",
        addedFn4Update: null,
    },
    onLoad: function () {
        this.updateTimer = 0;
        this.updateInterval = 1;
        this.bShowLoading = false;
        this.bContinualStep = false;
        this.speed = 0;
        this.initialStep = 1;
        this.stepCount = 0;
        this.stepCountMax = 8;
    },
    init: function (oScene, updateProgress) {
        this.videoPlayer = null;
        this.oScene = oScene;
        this.addedFn4Update = updateProgress;
        this.videoLeft = 0;
        this.videoTop = 0;
        this.videoWidth = 100;
        this.videoHeight = 100;
        this.iInitPlayStartTime = 0;
        this.bDoesDurationGot = false;
        this.bPlayerInited = false;
        this.bReady2Play = false;
        this.bPlayerEventInited = false;
        this.strStateBeforePlay = null;
        this.bHasVideo2Play = false;
        this.fnAfterReady2Play = null;
        this.fnDelayedInitPlayer = null;
        this.fnAfterInitPlayer = null;
        this.iValueAfterFakeStep = null;
        this.iValueBeforeStep = null;
        this.oProbeInfo = {};
    },
    initPlayer: function (iLeft, iTop, iWidth, iHeight, bShowLoading, bFullScreen, bHidden, iStartTime, bMute) {
        try {
            this.oScene._cLog.screenI("function initPlayer start");
            //this.oScene._cLog.screenI("取消延迟:延迟初始化播放器");
            this.fnDelayedInitPlayer = null;
            if (this.loadingIcon) {
                this.loadingIcon.opacity = 0;
            }
            try {
                this.oScene._cLog.screenI("初始化播放器 start");
                this.oScene._cLog.screenI("是否显示loading:" + bShowLoading);
                this.bMute = bMute;
                //初始化播放器
                this.bHidden = bHidden;
                if (this.bHidden) {
                    cc.Camera.main.backgroundColor = cc.Color.BLACK;
                } else {
                    cc.Camera.main.backgroundColor = cc.Color.TRANSPARENT;
                }
                this.bShowLoading = bShowLoading;
                this.videoLeft = iLeft || this.videoLeft;
                this.videoTop = iTop || this.videoTop;
                this.videoWidth = iWidth || this.videoWidth;
                this.videoHeight = iHeight || this.videoHeight;
                this.bFullScreen = bFullScreen;
                let nodeVideo = cc.find('PlayerContainer').getChildByName("VideoPlayer");
                // this.videoPlayer = nodeVideo.getComponent(cc.VideoPlayer);                   
                this.videoPlayer = nodeVideo.getComponent(CCMediaPlayer);                   //fix jerry
                this.oScene._cLog.screenI("222>" + this.videoPlayer);
                // this.videoPlayer.keepAspectRatio = !this.bHidden;        //维持原来的宽高比先不要      fix jerry
                // this.videoPlayer.node.x = this.videoLeft;//10000//this.videoLeft;//用ijk播放器时会出现全屏切歌时列表背景滞留上一首歌曲的画面
                // this.videoPlayer.node.y = this.videoTop;//10000//this.videoTop;
                // this.videoPlayer.node.width = this.videoWidth;
                // this.videoPlayer.node.height = this.videoHeight;
                this.videoPlayer.setArea(this.videoLeft, this.videoTop, this.videoWidth, this.videoHeight); //设置播放器位置     fix jerry
                if (!this.bPlayerEventInited) {
                    this.initPlayerEvent();
                }
                this.bHasVideo2Play = true;
                this.bPlayerInited = true;
                this.fnAfterInitPlayer && this.fnAfterInitPlayer.call(this);//担心存在还没InitPlayer的时候就去操作视频,比如setURL
                this.oScene._cLog.screenI("初始化播放器    end>");
            } catch (err) {
                this.oScene._cLog.screenI("initPlayer error==>" + err);
            }
            this.oScene._cLog.screenI("function initPlayer end");
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "initPlayer Error in OperateVideoPlay==>" + error);
            }
        }

    },
    initPlayerEvent: function () {
        try {
            this.oScene._cLog.screenI("initPlayerEvent....");
            this.bPlayerEventInited = true;
            this.videoPlayer.setOnPreparedListener(function () {            //fix jerry
                this.oScene._cLog.screenI('ready-to-play');
                this.bReady2Play = true;
                this.oScene._cLog.screenI("meta-loaded this.iInitPlayStartTime" + this.iInitPlayStartTime + "\r\n");

                this.videoPlayer.start();
                //看是否是纯k是纯k的话要进行定点播放
                if (!this.oScene._bContinuePlayed
                    && (
                        (this.oScene._strAppId && this.oScene._strAppId == BusinessParameter.KTV_APPID)
                        || (this.oScene._strPlaylistAppId && this.oScene._strPlaylistAppId == BusinessParameter.KTV_APPID))
                    && Common.g_iPlayerPlayedTime) {
                    this.iInitPlayStartTime = Common.g_iPlayerPlayedTime;
                } else {
                    Common.g_iPlayerPlayedTime = 0;
                }
                this.oScene._bContinuePlayed = true;
                //探针相关
                this.iRealPlayTime = 0;
                this.bValidPlayProbed = false;
                if (!this.bFullScreen && !this.bHidden) {
                    this.oScene._oProbe.requestProbe("interActive", {
                        "action": "VideoShow"
                    });
                }


                // this.videoPlayer.currentTime = this.iInitPlayStartTime;      
                this.videoPlayer.seekTo(this.iInitPlayStartTime);           //指定视频从什么时候开始播放      fix jerry
                if (this.totalTime) {
                    this.totalTime.string = this.formatTime(this.videoPlayer.getDuration());
                }

                this.oScene._cLog.screenI("是否静音:" + this.bMute);
                this.setMute(this.bMute);
                //this.oScene._cLog.screenI("延迟处理end" + this.fnAfterReady2Play);
                this.fnAfterReady2Play && this.fnAfterReady2Play.call(this);//担心视频还没准备好就要操作视频;比如 end
                this.fnAfterReady2Play = null;
                //准备播放后做个通知事件
                this.oScene.fnAfterReady2Play && this.oScene.fnAfterReady2Play.call(this.oScene);
            }.bind(this));

            // this.videoPlayer.node.on(
            //     'ready-to-play',
            //     function () {
            //         this.oScene._cLog.screenI('ready-to-play');
            //         this.bReady2Play = true;
            //         this.oScene._cLog.screenI("meta-loaded this.iInitPlayStartTime" + this.iInitPlayStartTime + "\r\n");
            //         this.videoPlayer && this.videoPlayer.play();
            //         //看是否是纯k是纯k的话要进行定点播放
            //         if (!this.oScene._bContinuePlayed
            //             && (
            //                 (this.oScene._strAppId && this.oScene._strAppId == BusinessParameter.KTV_APPID)
            //                 || (this.oScene._strPlaylistAppId && this.oScene._strPlaylistAppId == BusinessParameter.KTV_APPID))
            //             && Common.g_iPlayerPlayedTime) {
            //             this.iInitPlayStartTime = Common.g_iPlayerPlayedTime;
            //         } else {
            //             Common.g_iPlayerPlayedTime = 0;
            //         }
            //         this.oScene._bContinuePlayed = true;
            //         //探针相关
            //         this.iRealPlayTime = 0;
            //         this.bValidPlayProbed = false;
            //         if (!this.bFullScreen && !this.bHidden) {
            //             this.oScene._oProbe.requestProbe("interActive", {
            //                 "action": "VideoShow"
            //             });
            //         }


            //         this.videoPlayer.currentTime = this.iInitPlayStartTime;
            //         if (this.totalTime) {
            //             this.totalTime.string = this.formatTime(this.videoPlayer.getDuration());
            //         }
            //         this.oScene._cLog.screenI("是否静音:" + this.bMute);
            //         this.setMute(this.bMute);
            //         this.oScene._cLog.screenI("延迟处理end" + this.fnAfterReady2Play);
            //         this.fnAfterReady2Play && this.fnAfterReady2Play.call(this);//担心视频还没准备好就要操作视频;比如 end
            //         this.fnAfterReady2Play = null;
            //         //准备播放后做个通知事件
            //         this.oScene.fnAfterReady2Play && this.oScene.fnAfterReady2Play.call(this.oScene);
            //     },
            //     this
            // );

            this.videoPlayer.node.on(
                'stopped',
                function () {
                    this.oScene._cLog.screenI('stopped');
                },
                this
            );

            this.videoPlayer.node.on(
                'meta-loaded',
                function () {
                    this.oScene._cLog.screenI("Media Meta Loaded !!!!!!!");
                },
                this
            );


            this.videoPlayer.node.on(
                'clicked',
                function () {
                    cc.log("Media Clicked !!!!!!!");

                },
                this
            );

            this.videoPlayer.node.on(
                'playing',
                function () {
                    this.oScene._cLog.screenI('playing');
                    this.update();
                },
                this
            );

            this.videoPlayer.node.on(
                'paused',
                function () {
                    this.oScene._cLog.screenI('paused');
                },
                this
            );

            this.videoPlayer.setOnCompletionListener(function () {      //监听完成播放      fix jerry
                this.oScene._cLog.screenI("Media Complete!!!!!!!");
                this.duration = 0;
                // this.oScene.nextMedia && this.oScene.nextMedia();            //暂时屏蔽
            }.bind(this));
            // this.videoPlayer.node.on(
            //     'completed',
            //     function () {
            //         this.oScene._cLog.screenI("Media Complete!!!!!!!");
            //         this.duration = 0;
            //         this.oScene.nextMedia && this.oScene.nextMedia();
            //     },
            //     this
            // );
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "initPlayerEvent Error in OperateVideoPlay==>" + error);
            }
        }
    },
    setPosition: function (iLeft, iTop) {
        try {
            if (!this.videoPlayer) {
                return;
            }
            this.videoLeft = iLeft;
            this.videoTop = iTop;
            // this.videoPlayer.node.x = iLeft;
            // this.videoPlayer.node.y = iTop;
            this.videoPlayer.setArea(this.videoLeft, this.videoTop, this.videoWidth, this.videoHeight); //设置播放器位置     fix jerry
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "setPosition Error in OperateVideoPlay==>" + error);
            }
        }

    },
    setSize: function (iWidth, iHeight) {
        try {
            if (!this.videoPlayer) {
                return;
            }
            this.videoWidth = iWidth;
            this.videoHeight = iHeight;
            // this.videoPlayer.node.width = iWidth;
            // this.videoPlayer.node.height = iHeight;
            this.videoPlayer.setArea(this.videoLeft, this.videoTop, this.videoWidth, this.videoHeight); //设置播放器位置     fix jerry
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "setSize Error in OperateVideoPlay==>" + error);
            }
        }

    },
    setLeft: function (iLeft) {
        try {
            if (!this.videoPlayer) {
                return;
            }
            this.oScene._cLog.screenI("function setLeft start" + this.bReady2Play);
            this.videoLeft = iLeft;
            this.loadingIcon.parent.x = this.videoLeft - this.loadingIcon.parent.width / 2;
            if (this.bReady2Play) {
                // this.videoPlayer.node.x = iLeft;
                this.videoPlayer.setArea(this.videoLeft, this.videoTop, this.videoWidth, this.videoHeight); //设置播放器位置     fix jerry
            }
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "setLeft Error in OperateVideoPlay==>" + error);
            }
        }

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

    },
    setTop: function (iTop) {
        try {
            if (!this.videoPlayer) {
                return;
            }
            this.videoTop = iTop;
            // this.videoPlayer.node.y = iTop;
            this.videoPlayer.setArea(this.videoLeft, this.videoTop, this.videoWidth, this.videoHeight); //设置播放器位置     fix jerry
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "setTop Error in OperateVideoPlay==>" + error);
            }
        }

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

    },
    setWidth: function (iWidth) {
        try {
            if (!this.videoPlayer) {
                return;
            }
            this.videoWidth = iWidth;
            // this.videoPlayer.node.width = iWidth;
            this.videoPlayer.setArea(this.videoLeft, this.videoTop, this.videoWidth, this.videoHeight); //设置播放器位置     fix jerry
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "setWidth Error in OperateVideoPlay==>" + error);
            }
        }

    },
    getWidth: function () {
        try {
            if (!this.videoPlayer) {
                return;
            }
            // return this.videoPlayer.node.width;
            return this.videoWidth;         //fix jerry
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "getWidth Error in OperateVideoPlay==>" + error);
            }
        }

    },
    setHeight: function (iHeight) {
        try {
            if (!this.videoPlayer) {
                return;
            }
            this.videoHeight = iHeight;
            // this.videoPlayer.node.height = iHeight;
            this.videoPlayer.setArea(this.videoLeft, this.videoTop, this.videoWidth, this.videoHeight); //设置播放器位置     fix jerry
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "setHeight Error in OperateVideoPlay==>" + error);
            }
        }

    },
    getHeight: function () {
        try {
            if (!this.videoPlayer) {
                return;
            }
            // return this.videoPlayer.node.height;
            return this.videoHeight;                    //fix jerry
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "getHeight Error in OperateVideoPlay==>" + error);
            }
        }

    },
    play: function () {
        try {
            this.oScene._cLog.screenI("fn play");
            if (this.bFullScreen) {
                this.oScene._oProbe.requestProbe("MediaPlay", {
                    "position": this.now,  //当前播放时间
                    "duration": this.duration,
                });
            }
            // this.videoPlayer && this.videoPlayer.play();
            this.videoPlayer && this.videoPlayer.start();           //fix jerry
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "play Error in OperateVideoPlay==>" + error);
            }
        }

    },
    pause: function () {
        try {
            this.oScene._cLog.screenI("fn pause");
            if (this.bFullScreen) {
                this.oScene._oProbe.requestProbe("MediaPause", {
                    "position": this.now,  //当前播放时间
                    "duration": this.duration,
                });
            }
            // this.videoPlayer && this.videoPlayer.pause();
            this.iValueAfterFakeStep = this.now;        //解决未快进快退状态下,按暂停进度条变0的问题   fix jerry
            this.videoPlayer && this.videoPlayer.pause();
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "pause Error in OperateVideoPlay==>" + error);
            }
        }

    },
    resume: function () {
        try {
            // this.videoPlayer && this.videoPlayer.resume();
            this.videoPlayer && this.videoPlayer.start();       //resume就是恢复暂停播放的视频      fix jerry
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "resume Error in OperateVideoPlay==>" + error);
            }
        }

    },
    setMute: function (flag) {
        try {
            if (this.videoPlayer) {
                // this.videoPlayer.mute = flag;        //视频是否静音,暂未实现         fix jerry
                this.bMute = flag;
            }
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "setMute Error in OperateVideoPlay==>" + error);
            }
        }

    },
    goon: function () {
        this.setURL(this.url, this.now);
    },
    toggleFullscreen: function () {
        try {
            if (this.videoPlayer) {
                if (
                    cc.sys.isBrowser &&
                    cc.sys.browserType === cc.sys.BROWSER_TYPE_MOBILE_QQ &&
                    cc.sys.browserVersion <= 7.2 &&
                    /Nexus 6/.test(navigator.userAgent)
                ) {
                    return cc.log('May be crash, so prohibit full screen');
                }
                // this.videoPlayer.isFullscreen = true;       //功能暂未实现       fix jerry
            }
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "toggleFullscreen Error in OperateVideoPlay==>" + error);
            }
        }


    },
    stop: function () {
        this.videoPlayer && this.videoPlayer.stop();
    },
    keepRatioSwitch: function () {
        try {
            if (this.videoPlayer) {
                // this.videoPlayer.keepAspectRatio = !this.videoPlayer.keepAspectRatio;    //维持原来宽高比,暂未实现      fix jerry
            }
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "keepRatioSwitch Error in OperateVideoPlay==>" + error);
            }
        }


    },
    setURL: function (options, time, resourceType) {
        try {
            if(!options){
                return;
            }
            let url = options.playurl;
            cc.log("setURL start..."+url);
            options.appId = BusinessParameter.NEWTV_APPID;
            this.oScene._cLog.screenI("function setURL start");
            //this.oScene._cLog.screenI("取消延迟:延迟设置setURL");
            this.fnAfterInitPlayer = null;
            //this.oScene._cLog.screenI("取消延迟:延迟设置setURL");
            try {
                if (this.oScene.fnBeforePlay && !this._bCheckFnBeforePlay) {
                    this.oScene.fnBeforePlay && this.oScene.fnBeforePlay(function () {
                        this._bCheckFnBeforePlay = true;//防止死循环
                        this.setURL(options, time, resourceType);
                    }, this);
                } else {
                    this.oScene._cLog.screenI("setURL this.videoPlayer" + this.videoPlayer + "\r\n");
                    if (this.videoPlayer) {
                        time = time || 0;
                        this.videoPlayer.resourceType = resourceType || 0;  //视频来源,默认远程视频0
                        // this.oScene._cLog.screenI(this.videoPlayer.resourceType + "setURL222\r\n");
                        this.url = url || this.url;
                        // this.videoPlayer.remoteURL = url;
                        this.videoPlayer.setPlayURL(url);           //fix jerry
                        options.playURL = url;
                        options.duration = 0;
                        delete options.playurl;
                        this.videoPlayer.setInfo(JSON.stringify(options));
                        this.videoPlayer.prepareAsync();        //异步准备播放视频,准备完成后调用OnPreparedListener监听     fix jerry
                        // this.videoPlayer.isFullscreen = this.bFullScreen;        //全屏先不要        fix jerry
                        this.oScene._cLog.screenI("222" + this.videoPlayer.url + "setURL333\r\n");
                        // if (this.bShowLoading && this.loadingIcon) {         //暂时将加载进度条关了, this.bShowLoading出现诡异问题
                        //     let nodeParent = this.loadingIcon.parent;
                        //     nodeParent.zIndex = 1000;
                        //     nodeParent.x = this.videoLeft - nodeParent.width / 2;
                        //     nodeParent.y = this.videoTop - nodeParent.height / 2;
                        //     let anim = this.loadingIcon.getComponent(cc.Animation);
                        //     anim.play();
                        //     this.loadingIcon.opacity = 255;
                        // }
                    }
                }
            } catch (err) {
                this.oScene._cLog.screenI("setURL Error==>" + err + "\r\n");
            }
            this.oScene._cLog.screenI("function setURL end");
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "setURL Error in OperateVideoPlay==>" + error);
            }
        }

    },
    repeatMedia: function () {
        try {
            this.oScene._cLog.screenI("REPEAT");
            this.end();
            this.oScene._cLog.screenI("this.videoLeft:" + this.videoLeft + ",this.videoTop:" + this.videoTop + ",this.videoWidth:" + this.videoWidth + ",this.videoHeight:" + this.videoHeight);
            this.initPlayer(this.videoLeft, this.videoTop, this.videoWidth, this.videoHeight, this.bShowLoading);
            this.oScene._cLog.screenI("this.url:" + this.url);
            this.setURL(this.url);
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "repeatMedia Error in OperateVideoPlay==>" + error);
            }
        }

    },
    getURL: function () {
        return this.videoPlayer && this.videoPlayer.url;
    },
    end: function () {
        try {
            this.iValueAfterFakeStep = null;
            this.oScene._cLog.screenI("function end start");
            //this.oScene._cLog.screenI("取消延迟:延迟结束播放器 end");
            this.fnAfterReady2Play = null;
            if (this.videoPlayer) {
                this.oScene.fnBeforeMediaEnd && this.oScene.fnBeforeMediaEnd();
                if (cc.sys.isNative) {
                    this.videoPlayer.setArea(0, 0, 0, 0);       //这里为了解决切场景会显示停留的视频画面        fix jerry
                    this.videoPlayer.stop();            //先转成stop状态,才能重置      fix jerry
                    this.videoPlayer.reset();
                }
                if (this.bFullScreen) {
                    this.oScene._oProbe.requestProbe("MediaStop", {
                        "position": this.now,  //当前播放时间
                        "duration": this.duration,
                    });
                }
                if (this.bReady2Play &&
                    ((this.oScene._strAppId && this.oScene._strAppId == BusinessParameter.KTV_APPID)
                        || (this.oScene._strPlaylistAppId && this.oScene._strPlaylistAppId == BusinessParameter.KTV_APPID)
                    )
                ) {
                    Common.g_iPlayerPlayedTime = this.now;
                } else {
                    Common.g_iPlayerPlayedTime = 0;
                }
                this.oScene._cLog.screenI("end Common.g_iPlayerPlayedTime !!!!!!!" + Common.g_iPlayerPlayedTime);
                this.videoPlayer = null;
                this.bHasVideo2Play = false;
                this.bReady2Play = false;
                this.bPlayerInited = false;
                this.oScene._cLog.screenI("this.now==>" + this.now);
                this.oScene._cLog.screenI("Common.g_iPlayerPlayedTime==>" + Common.g_iPlayerPlayedTime);
                this.duration = 0;
                this.now = 0;
                if (this.bShowLoading && this.loadingIcon) {
                    let anim = this.loadingIcon.getComponent(cc.Animation);
                    anim.pause();
                    this.loadingIcon.opacity = 0;
                }
                cc.loader.release(this.url);
                //cc.sys.garbageCollect();
                this.bDoesDurationGot = false;
                this.iInitPlayStartTime = 0;
                this._bCheckFnBeforePlay = false;
                this.addedFn4Update && this.addedFn4Update.call(this.oScene, this.formatTime(0));
                //this.oScene._cLog.screenI("延迟处理initPlayer" + this.fnDelayedInitPlayer);
                this.fnDelayedInitPlayer && this.fnDelayedInitPlayer.call(this);//担心存在还没end完就去initPlayer了
            }
            this.oScene._cLog.screenI("function end end");
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "end Error in OperateVideoPlay==>" + error);
            }
        }

    },
    destroyMediaPlayer: function () {
        // this.videoPlayer && this.videoPlayer.destroy();
        this.videoPlayer && this.videoPlayer.release();         //fix jerry
    },
    toggleVisibility: function () {
        if (this.videoPlayer) {
            this.videoPlayer.enabled = !this.videoPlayer.enabled;       //组件共有特性,自身是否启用
        }
    },
    show: function () {
        try {
            if (this.videoPlayer) {
                this.oScene._cLog.screenI("enabled" + "\r\n");
                this.videoPlayer.enabled = true;
                this.oScene._cLog.screenI(this.videoPlayer.enabled + "\r\n");
            }
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "show Error in OperateVideoPlay==>" + error);
            }
        }

    },
    hide: function () {
        if (this.videoPlayer) {
            this.videoPlayer.enabled = false;
        }
    },
    isEnable: function () {
        return this.videoPlayer && this.videoPlayer.enabled;
    },
    setVolume: function (a, b) {
        this.videoPlayer && this.videoPlayer.setVolume(a, b);
    },
    getVideoNode: function () {
        return this.videoPlayer && this.videoPlayer.node;
    },
    playOnlineVideo: function () {
        if (this.videoPlayer) {
            // this.videoPlayer.resourceType = 0;                   //这个不一定能用到      fix jerry
            // this.videoPlayer.url = "http://benchmark.cocos2d-x.org/cocosvideo.mp4";
            // this.videoPlayer.play();
        }
    },
    resumePlayState: function () {
        this.oScene._cLog.screenI("this.strStateBeforePlay==>" + this.strStateBeforePlay);
        // this.videoPlayer.currentTime = this.iValueAfterFakeStep;  
        this.videoPlayer.seekTo(this.iValueAfterFakeStep);           //指定视频从什么时候开始播放      fix jerry
        this.iValueBeforeStep = null;
        this.oScene._oProbe.requestProbe("MediaStop", {
            "startTime": this.iValueBeforeStep,
            "endTime": this.iValueAfterFakeStep,
            "duration": this.duration,
        });

        this.playTimeReset = false;
        this.play();
    },
    step: function (iDir, val, bFakePress) {

        try {
            if (!this.videoPlayer && !this.bReady2Play) {
                return;
            }
            if (!this.iValueBeforeStep) {
                this.iValueBeforeStep = this.now;
            }
            this.speed = val || this.speed || this.initialStep || 2;
            if (this.duration > 0) {
                this.strStateBeforePlay = this.isPlaying() ? "play" : "pause";
                this.pause();
                if (bFakePress) {

                } else {
                    if (this.bContinualStep) {
                        this.stepCount++;
                        this.speed = this.stepCount > this.stepCountMax ? this.speed : this.initialStep * this.stepCount;

                    }
                    this.bContinualStep = true;
                    this.unschedule(this.timerStep);
                    this.scheduleOnce(this.timerStep, 0.5);
                }
                this.oScene._cLog.screenI("this.speed==>" + this.speed);
                let iTargetTime = this.now;
                // if (this.now + iDir * this.speed < this.duration) {
                //     iTargetTime = this.now + iDir * this.speed;
                // } else {
                //     iTargetTime = this.duration;
                //     // this.now = iTargetTime;                                         //解决进度条快进时间显示不统一      fix jerry
                //     // this.currentTime.string = this.formatTime(this.duration);       
                //     // this.videoPlayer.seekTo(this.iValueAfterFakeStep);              
                //     // this.addedFn4Update && this.addedFn4Update.call(this.oScene, this.formatTime(this.duration));
                //     // this.duration = 0;
                //     // this.now = 0;
                //     // this.addedFn4Update && this.addedFn4Update.call(this.oScene, this.formatTime(this.now));
                //     // this.oScene.nextMedia && this.oScene.nextMedia();
                //     // return;
                // }
                iTargetTime = Math.min(this.duration,this.now + iDir * this.speed);
                if (this.now + iDir * this.speed > 0) {
                    //iTargetTime = this.now + iDir * this.speed;
                } else {
                    iTargetTime = 0;
                }
                this.now = iTargetTime;
                this.iValueAfterFakeStep = this.now;
                if (this.currentTime) {
                    this.currentTime.string = this.formatTime(this.now);
                }
                this.addedFn4Update && this.addedFn4Update.call(this.oScene, this.formatTime(this.now));

                this.videoPlayer.seekTo(this.iValueAfterFakeStep);           //快进快退      fix jerry
            }
        } catch (error) {
            if (cc.sys.isNative) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "step Error in OperateVideoPlay==>" + error);
            }
        }

    },
    playByTime: function (iTime) {
        if (!this.videoPlayer) {
            return;
        }
        let flag = this.isPlaying();
        // this.videoPlayer.currentTime = iTime;        
        this.videoPlayer.seekTo(iTime);           //指定视频从什么时候开始播放      fix jerry
        // this.videoPlayer[flag ? "play" : "pause"]();
        this.videoPlayer[flag ? "start" : "pause"]();           //fix jerry
    },
    timerStep: function () {
        this.stepCount = 0;
        this.bContinualStep = false;
        this.speed = this.initialStep;
    },
    isPlaying: function () {
        return this.videoPlayer && this.videoPlayer.isPlaying();
    },
    update: function (dt) {
        try {
            this.updateTimer += dt;
            if (this.updateTimer < this.updateInterval) {
                return; // we don't need to do the math every frame
            }
            this.updateTimer = 0;
            if (!this.videoPlayer || !this.videoPlayer.enabled) return;
            if (this.oScene._bFakeProgressStart) {
                return;
            }
            let iTempNow = this.now;
            // this.now = this.videoPlayer.currentTime || 0;   
            this.now = this.videoPlayer.getCurrentPosition() || 0;           //fix jerry
            this.iRealPlayTime += this.now - iTempNow;
            this.duration = this.videoPlayer.getDuration() || 0;
            if (!this.bDoesDurationGot && this.duration > 0) {
                this.bDoesDurationGot = true;
                // this.videoPlayer.currentTime = this.iInitPlayStartTime ? (this.iInitPlayStartTime >= this.duration ? 0 : this.iInitPlayStartTime) : 0;
            }
            if (this.totalTime) {
                this.totalTime.string = this.formatTime(this.duration);
            }
            if (this.duration > 0) {
                this.stepCountMax = (Math.floor(this.duration / 60 / 5) || 1) * 8;
            }
            // this.oScene._cLog.screenI("OperateVideoPlay update this.loadingIcon:"+this.bShowLoading+"   "+this.loadingIcon);
            if (this.bShowLoading && this.loadingIcon) {
                this.loadingIcon.parent.x = this.videoLeft - this.loadingIcon.parent.width / 2;
                this.loadingIcon.parent.y = this.videoTop - this.loadingIcon.parent.height / 2;
                let anim = this.loadingIcon.getComponent(cc.Animation);
                if (this.now > 0) {
                    anim.pause();
                    this.loadingIcon.opacity = 0;
                } else if (this.duration == -100){      //未来播放器播前广告进行中。。。        fix jerry
                    anim.pause();
                    this.loadingIcon.opacity = 0;
                }
            }
            // this.videoPlayer.node.x = this.videoLeft;
            // this.videoPlayer.node.y = this.videoTop;
            this.videoPlayer.setArea(this.videoLeft, this.videoTop, this.videoWidth, this.videoHeight); //设置播放器位置     fix jerry
            //如果当前进度没有到快进到的播放时间点就不更新进度条
            if (this.iValueAfterFakeStep) {
                if (this.iValueAfterFakeStep <= this.now) {
                    if (this.currentTime) {
                        this.currentTime.string = this.formatTime(this.now);
                    }
                    this.addedFn4Update && this.addedFn4Update.call(this.oScene, this.formatTime(this.now));
                } else {

                }
            } else {
                if (this.currentTime) {
                    this.currentTime.string = this.formatTime(this.now);
                }
                this.addedFn4Update && this.addedFn4Update.call(this.oScene, this.formatTime(this.now));
            }
            if (this.iRealPlayTime > Common.VALID_PLAY_TIME_DURATION) {
                this.bValidPlayProbed = true;
                this.oScene._oProbe.requestProbe("MediaPlayAvailable");
            }
        } catch (error) {
            // if (cc.sys.isNative){
            //     jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V","update Error in OperateVideoPlay==>"+error);
            // }
        }
    },
    formatTime: function (iTime) {
        iTime = parseInt(iTime);
        let iMinutes = parseInt(iTime / 60);
        let iHours = parseInt(iMinutes / 60);
        let iSeconds = iTime - iMinutes * 60;
        iMinutes = iMinutes - iHours * 60;
        if (("" + iHours).length % 2) {
            iHours = "0" + iHours;
        }
        if (("" + iMinutes).length % 2) {
            iMinutes = "0" + iMinutes;
        }
        if (("" + iSeconds).length % 2) {
            iSeconds = "0" + iSeconds;
        }
        return iHours + ":" + iMinutes + ":" + iSeconds;
    },
});