@cc-component/cc-ex-component 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/core/ReferenceCollector.ts +172 -0
- package/assets/core/ReferenceCollector.ts.meta +9 -0
- package/assets/core.meta +9 -0
- package/assets/{BaseEx.ts → ex/BaseEx.ts} +21 -23
- package/assets/{BaseEx.ts.meta → ex/BaseEx.ts.meta} +1 -1
- package/assets/{ExTween.ts.meta → ex/ExTween.ts.meta} +1 -1
- package/assets/ex.meta +9 -0
- package/assets/video/IVideo.ts +73 -0
- package/assets/video/IVideo.ts.meta +9 -0
- package/assets/video/Interface.ts +26 -0
- package/assets/video/Interface.ts.meta +9 -0
- package/assets/video/VideoComponent.prefab +614 -0
- package/assets/video/VideoComponent.prefab.meta +13 -0
- package/assets/video/VideoComponent.ts +33 -0
- package/assets/video/VideoComponent.ts.meta +9 -0
- package/assets/video/VideoManager.ts +395 -0
- package/assets/video/VideoManager.ts.meta +9 -0
- package/assets/video/VideoModule.ts +114 -0
- package/assets/video/VideoModule.ts.meta +9 -0
- package/assets/video/VideoPlayTT.ts +319 -0
- package/assets/video/VideoPlayTT.ts.meta +9 -0
- package/assets/video/VideoPlayWX.ts +246 -0
- package/assets/video/VideoPlayWX.ts.meta +9 -0
- package/assets/video/VideoPlayWeb.ts +228 -0
- package/assets/video/VideoPlayWeb.ts.meta +9 -0
- package/assets/video/list.meta +9 -0
- package/assets/video.meta +9 -0
- package/index.ts +1 -1
- package/index.ts.meta +1 -1
- package/package.json +1 -1
- package/package.json.meta +1 -1
- /package/assets/{ExTween.ts → ex/ExTween.ts} +0 -0
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { _decorator, assetManager, Component, Node, Size, UITransform, VideoClip, VideoPlayer, view } from 'cc';
|
|
2
|
+
import { BaseVideo, IVideoParam } from './IVideo';
|
|
3
|
+
import { v3 } from 'cc';
|
|
4
|
+
import { sys } from 'cc';
|
|
5
|
+
const { ccclass, property } = _decorator;
|
|
6
|
+
|
|
7
|
+
@ccclass('VideoPlayWeb')
|
|
8
|
+
export class VideoPlayWeb extends BaseVideo {
|
|
9
|
+
|
|
10
|
+
onTimeUpdate: (data: { position: number, duration: number }) => void = null
|
|
11
|
+
onError: Function = null
|
|
12
|
+
onVideoEnd: Function = null
|
|
13
|
+
onRead: Function = null
|
|
14
|
+
data: { position: number, duration: number } = {
|
|
15
|
+
position: 0,
|
|
16
|
+
duration: 0
|
|
17
|
+
}
|
|
18
|
+
videoName: string = ""
|
|
19
|
+
videoPlayer: VideoPlayer
|
|
20
|
+
isPlaying: boolean = false
|
|
21
|
+
|
|
22
|
+
// node: Node;
|
|
23
|
+
taskId: string;
|
|
24
|
+
param: IVideoParam = {
|
|
25
|
+
isLoop: true,
|
|
26
|
+
isLocal: true,
|
|
27
|
+
isPlayTime: false,
|
|
28
|
+
isTargetSize: false
|
|
29
|
+
}
|
|
30
|
+
initParam: { bundle: string, dir: string }
|
|
31
|
+
nodeUT: UITransform;
|
|
32
|
+
isReady: boolean = false;
|
|
33
|
+
|
|
34
|
+
old_x = 0
|
|
35
|
+
getisPause() {
|
|
36
|
+
return !this.isPlaying
|
|
37
|
+
}
|
|
38
|
+
initVideo(initParam: { bundle: string, dir: string }) {
|
|
39
|
+
this.initParam = initParam
|
|
40
|
+
// this.node = node;
|
|
41
|
+
const node = this.node;
|
|
42
|
+
this.old_x = node.position.x
|
|
43
|
+
this.nodeUT = this.node.getComponent(UITransform);
|
|
44
|
+
let comp = node.addComponent(VideoPlayer);
|
|
45
|
+
this.videoPlayer = comp
|
|
46
|
+
comp.enabled = true
|
|
47
|
+
// node.on(VideoPlayer.EventType.READY_TO_PLAY, this.readyPlay, this);
|
|
48
|
+
node.on(VideoPlayer.EventType.PLAYING, this.playIng.bind(this), this);
|
|
49
|
+
node.on(VideoPlayer.EventType.COMPLETED, this.videoEnd.bind(this), this);
|
|
50
|
+
node.on(VideoPlayer.EventType.ERROR, this.videoError.bind(this), this);
|
|
51
|
+
|
|
52
|
+
comp.resourceType = VideoPlayer.ResourceType.REMOTE;
|
|
53
|
+
comp.stayOnBottom = true;
|
|
54
|
+
comp.playOnAwake = true;
|
|
55
|
+
comp.currentTime = 0;
|
|
56
|
+
comp.volume = 1;
|
|
57
|
+
comp.mute = true;
|
|
58
|
+
comp.keepAspectRatio = false;
|
|
59
|
+
//comp.fullScreenOnAwake = true;
|
|
60
|
+
comp.loop = true;
|
|
61
|
+
comp.fullScreenOnAwake = false;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public loadVideo(name: string, param: IVideoParam) {
|
|
65
|
+
this.param = param;
|
|
66
|
+
// this.videoPlayer.fullScreenOnAwake = false;
|
|
67
|
+
//this.play()
|
|
68
|
+
|
|
69
|
+
this.isReady = false;
|
|
70
|
+
if (param.isLocal) {
|
|
71
|
+
this.videoPlayer.resourceType = VideoPlayer.ResourceType.LOCAL;
|
|
72
|
+
//this.videoPlayer.clip = assetManager.getBundle(this.initParam.bundle).get(`${this.initParam.dir}/${name}`, VideoClip);
|
|
73
|
+
assetManager.getBundle(this.initParam.bundle).load(`${this.initParam.dir}/${name}`, VideoClip, (err, clip) => {
|
|
74
|
+
if (err) {
|
|
75
|
+
console.error('视频加载失败:');
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
this.activeVideo(true)
|
|
79
|
+
if (!param.isTargetSize)
|
|
80
|
+
this.autoSize()
|
|
81
|
+
this.videoPlayer.clip = clip;
|
|
82
|
+
//this.videoPlayer.remoteURL = "";
|
|
83
|
+
this.videoPlayer.loop = param.isLoop
|
|
84
|
+
const is_skip = name === this.videoName;
|
|
85
|
+
//console.warn('暂停', is_skip)
|
|
86
|
+
|
|
87
|
+
if (is_skip) {
|
|
88
|
+
this.isReady = true;
|
|
89
|
+
this.readyPlay()
|
|
90
|
+
} else {
|
|
91
|
+
//this.pause();
|
|
92
|
+
}
|
|
93
|
+
this.videoName = name
|
|
94
|
+
});
|
|
95
|
+
} else {
|
|
96
|
+
this.activeVideo(true)
|
|
97
|
+
if (!param.isTargetSize)
|
|
98
|
+
this.autoSize()
|
|
99
|
+
const is_skip = name === this.videoPlayer.remoteURL;
|
|
100
|
+
this.videoPlayer.remoteURL = name;
|
|
101
|
+
this.videoPlayer.resourceType = VideoPlayer.ResourceType.REMOTE;
|
|
102
|
+
//console.warn('暂停', is_skip)
|
|
103
|
+
if (is_skip) {
|
|
104
|
+
this.isReady = true;
|
|
105
|
+
this.readyPlay()
|
|
106
|
+
} else {
|
|
107
|
+
this.play()
|
|
108
|
+
//this.pause();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
play(isloop?: boolean) {
|
|
114
|
+
if (isloop != undefined || isloop != null) {
|
|
115
|
+
this.videoPlayer.loop = isloop
|
|
116
|
+
}
|
|
117
|
+
//console.warn("播放2")
|
|
118
|
+
this.videoPlayer.play();
|
|
119
|
+
// this.videoPlayer.resume();
|
|
120
|
+
this.isPlaying = true
|
|
121
|
+
}
|
|
122
|
+
async pause() {
|
|
123
|
+
this.videoPlayer.pause();
|
|
124
|
+
this.isPlaying = false
|
|
125
|
+
console.log("暂停")
|
|
126
|
+
|
|
127
|
+
}
|
|
128
|
+
stop() {
|
|
129
|
+
this.videoPlayer.stop();
|
|
130
|
+
this.isPlaying = false
|
|
131
|
+
console.log("停止")
|
|
132
|
+
|
|
133
|
+
}
|
|
134
|
+
resume() {
|
|
135
|
+
this.videoPlayer.resume();
|
|
136
|
+
this.isPlaying = true
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
seek(time: number) {
|
|
140
|
+
this.videoPlayer.currentTime = time
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
private videoEnd() {
|
|
144
|
+
// if (!this.isloop) this.node.off(VideoPlayer.EventType.COMPLETED, this.videoEnd, this);
|
|
145
|
+
this.onVideoEnd?.();
|
|
146
|
+
}
|
|
147
|
+
private playIng() {
|
|
148
|
+
if (!this.isReady) {
|
|
149
|
+
this.readyPlay()
|
|
150
|
+
}
|
|
151
|
+
this.isReady = true;
|
|
152
|
+
}
|
|
153
|
+
private readyPlay() {
|
|
154
|
+
this.videoPlayer.pause()
|
|
155
|
+
this.isPlaying = false;
|
|
156
|
+
|
|
157
|
+
// if (!this.isloop) this.node.off(VideoPlayer.EventType.READY_TO_PLAY, this.readyPlay, this);
|
|
158
|
+
this.onRead?.(this)
|
|
159
|
+
}
|
|
160
|
+
private videoError() {
|
|
161
|
+
this.onError?.();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
protected onDestroy(): void {
|
|
165
|
+
this.node.off(VideoPlayer.EventType.ERROR, this.videoError, this)
|
|
166
|
+
this.node.off(VideoPlayer.EventType.PLAYING, this.playIng, this)
|
|
167
|
+
this.node.off(VideoPlayer.EventType.COMPLETED, this.videoEnd, this)
|
|
168
|
+
// this.node.off(VideoPlayer.EventType.READY_TO_PLAY, this.readyPlay, this)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
protected update(dt: number): void {
|
|
172
|
+
if (this.isPlaying && this.param.isPlayTime) {
|
|
173
|
+
this.data.position = this.videoPlayer.currentTime;
|
|
174
|
+
this.data.duration = this.videoPlayer.duration;
|
|
175
|
+
this.onTimeUpdate?.(this.data)
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async destroyVideo() {
|
|
180
|
+
if (this.videoPlayer) {
|
|
181
|
+
this.activeVideo(false)
|
|
182
|
+
this.stop()
|
|
183
|
+
this.isReady = false;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
activeVideo(isActive: boolean) {
|
|
187
|
+
if (sys.platform === sys.Platform.DESKTOP_BROWSER) {
|
|
188
|
+
this.videoPlayer.node.active = isActive
|
|
189
|
+
} else {
|
|
190
|
+
this.videoPlayer.node.position = v3(isActive ? this.old_x : 10000, 0, 0)
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
setSize(param: { x: number, y: number, width: number, height: number }) {
|
|
194
|
+
if (this.videoPlayer) {
|
|
195
|
+
this.nodeUT.contentSize = new Size(param.width, param.height)
|
|
196
|
+
this.node.setWorldPosition(param.x - param.width / 2, param.y + param.height / 2, 0)
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
// 节点位置适配
|
|
200
|
+
autoSize() {
|
|
201
|
+
//const size = { width: 1080, height: 1920 }
|
|
202
|
+
let screenSize = view.getVisibleSize(); // 获取当前屏幕尺寸
|
|
203
|
+
if (this.param.isFullNot) {
|
|
204
|
+
screenSize = new Size(1080, 1920)
|
|
205
|
+
}
|
|
206
|
+
const designResolutionSize = view.getDesignResolutionSize()
|
|
207
|
+
const w = screenSize.width / designResolutionSize.width
|
|
208
|
+
const h = screenSize.height / designResolutionSize.height
|
|
209
|
+
|
|
210
|
+
// 根据屏幕宽高调整目标节点的位置
|
|
211
|
+
const ratio = h
|
|
212
|
+
const width = designResolutionSize.width * ratio
|
|
213
|
+
const height = designResolutionSize.height * ratio
|
|
214
|
+
const width_w = screenSize.width - width;
|
|
215
|
+
const height_h = screenSize.height - view.getVisibleSize().height;
|
|
216
|
+
|
|
217
|
+
const x = width_w / 2
|
|
218
|
+
let y = 0//-height / 4
|
|
219
|
+
if (this.param.isFullNot) {
|
|
220
|
+
y = height_h / 2
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
this.nodeUT.contentSize = new Size(width, height)
|
|
224
|
+
this.node.setPosition(x, y, 0)
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
|
package/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// 负责导出assets下的模块,如: export { default } from './assets/xxx.ts'
|
|
2
|
-
export {
|
|
2
|
+
// export { } from './assets/BaseEx';
|
package/index.ts.meta
CHANGED
package/package.json
CHANGED
package/package.json.meta
CHANGED
|
File without changes
|