12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- // Learn TypeScript:
- // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
- // Learn Attribute:
- // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
- // Learn life-cycle callbacks:
- // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
- import common, { AttributeUnit } from "../../../src/common/common";
- import CConst from "../../../src/common/CConst";
- import NotifierCenter from "../../../src/webtcp/NotifierCenter";
- import GameBase from "../../../src/common/GameBase";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class VideoPlayer extends GameBase {
- @property({ tooltip: '播放按钮', type: cc.Node })
- nodeStart: cc.Node = null;
- @property({ tooltip: '视频资源', type: cc.VideoPlayer })
- video: cc.VideoPlayer = null;
- protected onEnable(): void {
- this.nodeStart.active = true;
- this.loadVideo();
- }
- protected onDisable(): void {
- this.stopVideo();
- }
- async loadVideo(){
- let unitCur = common.getUnitNum();
- let pageNum = common.getPageNum();
- let attribute: AttributeUnit = common.attributeMap[unitCur];
- let configOne = attribute.config[pageNum - 1];
- this.video.remoteURL = configOne.videoName;
- };
- /** 事件-点击屏幕 */
- eventTouch(){
- this.playVideo();
- }
- /** 事件-视频相关 */
- eventVideo(videoplayer: cc.VideoPlayer, event: cc.VideoPlayer.EventType, customEventData): void {
- common.log('视频:', this.getStatus(event), '; url: ', videoplayer.remoteURL);
- if(event === cc.VideoPlayer.EventType.PLAYING){
- this.nodeStart.active = false;
- }
- else if(event === cc.VideoPlayer.EventType.READY_TO_PLAY){
- this.playVideo();
- }
- else if (event === cc.VideoPlayer.EventType.COMPLETED) {
- common.setGameToLocal();
- NotifierCenter.trigger(CConst.EVENT_ENTER_GAME, {});
- }
- }
-
- playVideo(){
- if (!this.video.isPlaying()) {
- this.video.play();
- }
- }
- stopVideo(){
- this.video.stop();
- }
- getStatus (event) {
- switch (event) {
- case cc.VideoPlayer.EventType.PLAYING:
- return 'PLAYING';
- case cc.VideoPlayer.EventType.PAUSED:
- return 'PAUSED';
- case cc.VideoPlayer.EventType.STOPPED:
- return 'STOPPED';
- case cc.VideoPlayer.EventType.COMPLETED:
- return 'COMPLETED';
- case cc.VideoPlayer.EventType.META_LOADED:
- return 'META_LOADED';
- case cc.VideoPlayer.EventType.CLICKED:
- return 'CLICKED';
- case cc.VideoPlayer.EventType.READY_TO_PLAY:
- return 'READY_TO_PLAY';
- default:
- return 'NONE';
- }
- };
- }
|