SDK相关的整理

This commit is contained in:
chen wei bo
2025-09-26 17:51:10 +08:00
parent c04bf2294a
commit 5bd7851f1e
3 changed files with 65 additions and 217 deletions
-128
View File
@@ -1,128 +0,0 @@
import { _decorator, Component, Node, tween, UIOpacity, Vec3, VideoPlayer } from 'cc';
import Utils from '../Common/Utils';
import { VideoRoleType } from '../Common/GlobalValue';
import { logger } from "db://assets/Scripts/Main/Common/Logger";
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) {
// logger.log("BgVideo 主视频时长:", this.vp.currentTime, this.vp.duration);
// }
}
/**播放视频 */
playVideo(remoteUrl:string, loop:boolean = false, autoIn:boolean = true) {
logger.log("BgVideo 播放视频:", this.node.position)
this.vp.remoteURL = remoteUrl
this.vp.loop = loop
this.vp.stop()
this.vp.play()
this._isPlaying = true
if (autoIn) {
this.moveIn()
}
}
/**暂停视频 */
pauseVideo() {
logger.log("BgVideo 暂停视频:", this._vtype)
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) {
// logger.log("bgvideo BgVideo组件 event", event2, this._vtype)
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()
}
}
}
}
}
@@ -1,9 +0,0 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "72cc3ead-c647-42b1-8c26-7a10d59d419e",
"files": [],
"subMetas": {},
"userData": {}
}