[0]视频节点VideoNode无法监听事件

const { regClass, property } = Laya;
import { MainBase } from "./Main.generated";
@regClass()
export class Main extends MainBase {
  onAwake() {
    this.VideoNode.play();
    console.log("Game start"); // 监听视频播放结束事件
      this.VideoNode.on('playing', this, () => {
      // 在视频结束时添加文本
      console.log("-------------");
    });
    this.VideoNode.on('click', this, () => {
      this.Button.alpha = 1;
      this.VideoNode.pause();
      // 在视频结束时添加文本
      console.log("---------END----");
    });
  }
}
已邀请:

Laya_Fred

赞同来自:

您好,您在监听video标签的事件时,需要在VideoTexture上进行监听,您可以参考下面的代码示例:
const { regClass, property } = Laya;

@regClass()
export class VideoTest extends Laya.Script {
//declare owner : Laya.Sprite3D;

@property({ type: Laya.VideoNode })
public video: Laya.VideoNode;

public isStop: Boolean;

constructor() {
super();
}

/**
* 组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
*/
onAwake(): void {
this.video.play();

// 需要添加到videoTexture上
this.video.videoTexture.on("playing", () => {
console.log("开始播放--------");
this.video.loop = true;
});

this.video.videoTexture.on("timeupdate", () => {
console.log("播放更新--------");
});

// videoNode可以添加Laya.Event.CLICK事件来监听点击事件
this.video.on(Laya.Event.CLICK, () => {
this.isStop = !this.isStop;
this.isStop && (this.video.pause());
!this.isStop && (this.video.play());
console.log("暂停视频播放-----------");
});
}
}

要回复问题请先

商务合作
商务合作