2025-07-17 17:18:21 +08:00
|
|
|
import { _decorator, Component, Node, tween, UIOpacity, Vec3, VideoPlayer } from 'cc';
|
|
|
|
|
import Utils from '../Common/Utils';
|
|
|
|
|
import { VideoRoleType } from '../Common/GlobalValue';
|
2025-09-21 20:18:24 +08:00
|
|
|
import { logger } from "db://assets/Scripts/Main/Common/Logger";
|
|
|
|
|
|
2025-07-17 17:18:21 +08:00
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
|
|
|
|
/**背景视频 */
|
|
|
|
|
@ccclass('BgVideo')
|
|
|
|
|
export class BgVideo extends Component {
|
|
|
|
|
|
|
|
|
|
private vp: VideoPlayer = null!;
|
|
|
|
|
|
|
|
|
|
private _isPlaying: boolean = false;
|
|
|
|
|
public get isPlaying(): boolean {
|
|
|
|
|
return this._isPlaying;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private _vtype: VideoRoleType = VideoRoleType.None;
|
|
|
|
|
public get vtype(): VideoRoleType {
|
|
|
|
|
return this._vtype;
|
|
|
|
|
}
|
|
|
|
|
public set vtype(v: VideoRoleType) {
|
|
|
|
|
this._vtype = v;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private _remoteUrl: string = '';
|
|
|
|
|
public set remoteUrl(url: string) {
|
|
|
|
|
this._remoteUrl = url;
|
|
|
|
|
this.vp.remoteURL = url;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private _cbReady: Function | undefined = null;
|
|
|
|
|
public set cbReady(cb: Function | undefined) {
|
|
|
|
|
this._cbReady = cb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private _cbEnd: Function | undefined = null;
|
|
|
|
|
public set cbEnd(cb: Function | undefined) {
|
|
|
|
|
this._cbEnd = cb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected onLoad(): void {
|
|
|
|
|
this.vp = this.node.getComponent(VideoPlayer)!;
|
|
|
|
|
this.moveOut();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
start() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
update(deltaTime: number) {
|
|
|
|
|
// if (this._isPlaying && this.vtype == VideoRoleType.Idle) {
|
2025-09-21 20:18:24 +08:00
|
|
|
// logger.log("BgVideo 主视频时长:", this.vp.currentTime, this.vp.duration);
|
2025-07-17 17:18:21 +08:00
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**播放视频 */
|
|
|
|
|
playVideo(remoteUrl:string, loop:boolean = false, autoIn:boolean = true) {
|
2025-09-21 20:18:24 +08:00
|
|
|
logger.log("BgVideo 播放视频:", this.node.position)
|
2025-07-17 17:18:21 +08:00
|
|
|
this.vp.remoteURL = remoteUrl
|
|
|
|
|
this.vp.loop = loop
|
|
|
|
|
this.vp.stop()
|
|
|
|
|
this.vp.play()
|
|
|
|
|
this._isPlaying = true
|
|
|
|
|
if (autoIn) {
|
|
|
|
|
this.moveIn()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**暂停视频 */
|
|
|
|
|
pauseVideo() {
|
2025-09-21 20:18:24 +08:00
|
|
|
logger.log("BgVideo 暂停视频:", this._vtype)
|
2025-07-17 17:18:21 +08:00
|
|
|
this.vp.pause()
|
|
|
|
|
}
|
|
|
|
|
/**继续播放 */
|
|
|
|
|
replayVideo() {
|
|
|
|
|
this.vp.play()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
moveIn() {
|
|
|
|
|
this.node.position = new Vec3(0, 0, 0)
|
|
|
|
|
// //测试代码
|
|
|
|
|
// if (this._vtype == VideoRoleType.emo) {
|
|
|
|
|
// this.node.position = new Vec3(0, -500, 0)
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
moveOut() {
|
|
|
|
|
this.node.position = new Vec3(1000, 1000, 0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**回收视频 */
|
|
|
|
|
recycleVideo() {
|
|
|
|
|
this.vp.stop()
|
|
|
|
|
this.vp.remoteURL = ""
|
|
|
|
|
this._isPlaying = false
|
|
|
|
|
this.moveOut()
|
|
|
|
|
// this.node.destroy()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onVideoEvent(event1:any, event2:any) {
|
2025-09-21 20:18:24 +08:00
|
|
|
// logger.log("bgvideo BgVideo组件 event", event2, this._vtype)
|
2025-07-17 17:18:21 +08:00
|
|
|
if (event2 == "ready-to-play") {
|
|
|
|
|
// if (!this._emoShow) {
|
|
|
|
|
// this._emoShow = true;
|
|
|
|
|
// this.removeEmoAudioNext()
|
|
|
|
|
// }
|
|
|
|
|
// this.setEmoReadyAudio(this.emo1)
|
|
|
|
|
if (this._cbReady) {
|
|
|
|
|
this._cbReady()
|
|
|
|
|
}
|
|
|
|
|
} else if (event2 == "completed") {
|
|
|
|
|
if (this._cbEnd) {
|
|
|
|
|
this._cbEnd()
|
|
|
|
|
}
|
|
|
|
|
} else if (event2 == "playing") {
|
|
|
|
|
if (this._vtype == VideoRoleType.Idle) {
|
|
|
|
|
if (this._cbEnd) { //主视频是循环播放的,没有completed事件,所以用playing事件来处理
|
|
|
|
|
this._cbEnd()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|