@cc-component/cc-ex-component 1.0.9 → 1.1.1
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/video/IVideo.ts +2 -2
- package/assets/video/VideoComponent.ts +1 -1
- package/assets/video/VideoManager.ts +5 -1
- package/assets/video/VideoModule.ts +30 -7
- package/assets/video/VideoPlayTT.ts +22 -3
- package/assets/video/VideoPlayWX.ts +34 -6
- package/assets/video/VideoPlayWeb.ts +2 -2
- package/package.json +1 -1
package/assets/video/IVideo.ts
CHANGED
|
@@ -15,7 +15,7 @@ export class VideoComponent extends Component {
|
|
|
15
15
|
@property({ displayName: '封面目录' })
|
|
16
16
|
cover_dir: string = 'cover_dir'
|
|
17
17
|
@property({ displayName: '远程地址根目录', tooltip: '视频远程地址全路径示例: https://hcy-cdn-domestic.wyx.cn/online/comeback/xxx.mp4' })
|
|
18
|
-
remote_url: string = 'https://hcy-cdn-domestic.wyx.cn/online/comeback/'
|
|
18
|
+
remote_url: string = 'https://hcy-cdn-domestic.wyx.cn/online/comeback/video/'
|
|
19
19
|
protected onLoad(): void {
|
|
20
20
|
//const camera = director.getScene().getComponentsInChildren(Camera)[0]
|
|
21
21
|
// camera.clearColor = new Color(0, 0, 0, 0)
|
|
@@ -65,6 +65,7 @@ export class VideoManager {
|
|
|
65
65
|
}
|
|
66
66
|
return false;
|
|
67
67
|
}
|
|
68
|
+
|
|
68
69
|
remote_url = ""
|
|
69
70
|
initVideo(param: InitParam) {
|
|
70
71
|
this.paramInit = param;
|
|
@@ -142,6 +143,7 @@ export class VideoManager {
|
|
|
142
143
|
if (VideoManager.instance.Debug)
|
|
143
144
|
console.log("视频准备好了")
|
|
144
145
|
this.cover.node.active = false
|
|
146
|
+
this.seek(0)
|
|
145
147
|
if (this.param.isLocal) {
|
|
146
148
|
//this.play()
|
|
147
149
|
//console.log("开始播放")
|
|
@@ -173,7 +175,7 @@ export class VideoManager {
|
|
|
173
175
|
this.param = param;
|
|
174
176
|
this.cover.spriteFrame = assetManager.getBundle(this.paramInit.bundle)?.get(`${this.paramInit.cover_dir}/${param.coverImage}/spriteFrame`)
|
|
175
177
|
this.cover.node.active = this.cur_name === name ? false : true;
|
|
176
|
-
|
|
178
|
+
|
|
177
179
|
this.baseVideo.loadVideo(name, param)
|
|
178
180
|
this.cur_name = name;
|
|
179
181
|
}
|
|
@@ -212,8 +214,10 @@ export class VideoManager {
|
|
|
212
214
|
// if (VideoManager.instance.Debug)
|
|
213
215
|
// console.log('加载视频', name)
|
|
214
216
|
const isloop = false
|
|
217
|
+
const onRead = param.onRead
|
|
215
218
|
param.onRead = () => {
|
|
216
219
|
console.warn('当前播放', name)
|
|
220
|
+
onRead?.()
|
|
217
221
|
this.playVideo(param)
|
|
218
222
|
}
|
|
219
223
|
this.loadVideo(name, param)
|
|
@@ -2,6 +2,10 @@ import { _decorator, assetManager, Component, Node, randomRangeInt } from 'cc';
|
|
|
2
2
|
import { VideoManager } from './VideoManager';
|
|
3
3
|
import { InitParam, IVideoData, IVideoParam } from './IVideo';
|
|
4
4
|
import { BYTEDANCE, WECHAT } from 'cc/env';
|
|
5
|
+
import { sys } from 'cc';
|
|
6
|
+
import { VideoPlayTT } from './VideoPlayTT';
|
|
7
|
+
import { VideoPlayWeb } from './VideoPlayWeb';
|
|
8
|
+
import { VideoPlayWX } from './VideoPlayWX';
|
|
5
9
|
const { ccclass, property } = _decorator;
|
|
6
10
|
|
|
7
11
|
|
|
@@ -54,26 +58,32 @@ export class VideoModule {
|
|
|
54
58
|
static StopVideoTask() { VideoManager.instance.stopVideoList() }
|
|
55
59
|
|
|
56
60
|
/**提前加载视频 */
|
|
57
|
-
static LoadVideo(
|
|
61
|
+
static LoadVideo(name: string, param: IVideoParam) {
|
|
58
62
|
VideoManager.instance.stopVideoList()
|
|
59
|
-
param.isLocal =
|
|
60
|
-
VideoManager.instance.loadVideo(
|
|
63
|
+
param.isLocal = VideoModule.isLocal(name)
|
|
64
|
+
VideoManager.instance.loadVideo(name, param)
|
|
61
65
|
}
|
|
62
66
|
|
|
63
67
|
/**播放单个视频 */
|
|
64
68
|
static PlayVideo(video: IVideoData, param: IVideoParam) {
|
|
65
69
|
VideoManager.instance.stopVideoList()
|
|
66
|
-
param.isLocal =
|
|
67
|
-
|
|
70
|
+
param.isLocal = VideoModule.isLocal(video.name)
|
|
71
|
+
const onRead = param.onRead
|
|
72
|
+
param.onRead = () => {
|
|
73
|
+
onRead?.()
|
|
74
|
+
VideoManager.instance.playVideo(param)
|
|
75
|
+
}
|
|
68
76
|
VideoManager.instance.loadVideo(video.name, param)
|
|
69
77
|
}
|
|
70
78
|
|
|
71
79
|
/** 播放多个视频*/
|
|
72
80
|
static PlayVideoMore(video_list: IVideoData[], param: IVideoParam) {
|
|
73
81
|
const url = video_list[0].name
|
|
74
|
-
param.isLocal =
|
|
82
|
+
param.isLocal = VideoModule.isLocal(url)
|
|
75
83
|
if (param.isPlayTime) {
|
|
84
|
+
const onRead = param.onRead
|
|
76
85
|
param.onRead = () => {
|
|
86
|
+
onRead?.()
|
|
77
87
|
VideoManager.instance.playVideoList(video_list, param)
|
|
78
88
|
}
|
|
79
89
|
VideoManager.instance.loadVideo(url, param)
|
|
@@ -82,13 +92,26 @@ export class VideoModule {
|
|
|
82
92
|
}
|
|
83
93
|
}
|
|
84
94
|
|
|
95
|
+
static isLocal(url: string) {
|
|
96
|
+
let result = url
|
|
97
|
+
switch (sys.platform) {
|
|
98
|
+
case sys.Platform.WECHAT_GAME:
|
|
99
|
+
case sys.Platform.BYTEDANCE_MINI_GAME:
|
|
100
|
+
result = `${VideoManager.instance.paramInit.remote_url}${url}`
|
|
101
|
+
break;
|
|
102
|
+
default:
|
|
103
|
+
// result = `${VideoManager.instance.paramInit.remote_url}${url}`
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
return !result.includes("http")
|
|
107
|
+
}
|
|
85
108
|
|
|
86
109
|
|
|
87
110
|
//#region 本地视频
|
|
88
111
|
/**播放单个视频 -本地视频 */
|
|
89
112
|
// public play(url: string, param: IVideoParam) {
|
|
90
113
|
// VideoManager.instance.loadVideo(url, {
|
|
91
|
-
// isLoop: param.isLoop,
|
|
114
|
+
// isLoop: param.isLoop, isVideoFit: param.isVideoFit, isLocal: param.isLocal, isPlayTime: param.isPlayTime, coverImage: param.coverImage, onRead: () => {
|
|
92
115
|
// VideoManager.instance.playVideo({
|
|
93
116
|
// isLoop: param.isLoop,
|
|
94
117
|
// finish: param.onRead
|
|
@@ -126,7 +126,7 @@ export class VideoPlayTT extends BaseVideo {
|
|
|
126
126
|
this.is_stop = false;
|
|
127
127
|
this.videoPlayer = this.createVideoWX(name, true)
|
|
128
128
|
this.actioveSelf(true)
|
|
129
|
-
|
|
129
|
+
|
|
130
130
|
|
|
131
131
|
this.videoPlayer.src = name;
|
|
132
132
|
this.videoPlayer.onCanplay(this.onCanplay.bind(this))
|
|
@@ -134,6 +134,8 @@ export class VideoPlayTT extends BaseVideo {
|
|
|
134
134
|
this.videoPlayer.loop = param.isLoop
|
|
135
135
|
const is_skip = name === this.remoteURL;
|
|
136
136
|
this.remoteURL = name;
|
|
137
|
+
if (!param.isTargetSize)
|
|
138
|
+
this.autoSize()
|
|
137
139
|
|
|
138
140
|
}
|
|
139
141
|
|
|
@@ -194,12 +196,14 @@ export class VideoPlayTT extends BaseVideo {
|
|
|
194
196
|
this.canPlay = false;
|
|
195
197
|
|
|
196
198
|
}
|
|
199
|
+
|
|
197
200
|
resume() {
|
|
198
201
|
this.videoPlayer.resume();
|
|
199
202
|
this.isPlaying = true
|
|
200
203
|
}
|
|
201
204
|
|
|
202
205
|
seek(time: number) {
|
|
206
|
+
//console.error('seek', time)
|
|
203
207
|
this.videoPlayer.seek(time)
|
|
204
208
|
}
|
|
205
209
|
|
|
@@ -283,6 +287,21 @@ export class VideoPlayTT extends BaseVideo {
|
|
|
283
287
|
}
|
|
284
288
|
|
|
285
289
|
setSize(param: { x: number, y: number, width: number, height: number }) {
|
|
290
|
+
if (this.videoPlayer) {
|
|
291
|
+
var size = view.getVisibleSize();
|
|
292
|
+
var designResolutionSize = view.getDesignResolutionSize();
|
|
293
|
+
var ratio = size.width / designResolutionSize.width;
|
|
294
|
+
var width = param.width * ratio;
|
|
295
|
+
var height = param.height * ratio;
|
|
296
|
+
var x = param.x * ratio - width / 2;;
|
|
297
|
+
var y = param.y - size.height + param.height / 2 * ratio //* ratio// + param.height / 2 * ratio
|
|
298
|
+
this.video_sp_ut.node.position = new Vec3(x, y, 0);
|
|
299
|
+
this.video_sp_ut.contentSize = new Size(width, height);
|
|
300
|
+
console.error(param.y, size)
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
videoFit(param: { x: number, y: number, width: number, height: number }) {
|
|
286
305
|
if (this.videoPlayer) {
|
|
287
306
|
const size = view.getVisibleSize();
|
|
288
307
|
const designResolutionSize = view.getDesignResolutionSize();
|
|
@@ -300,8 +319,8 @@ export class VideoPlayTT extends BaseVideo {
|
|
|
300
319
|
autoSize() {
|
|
301
320
|
if (this.videoPlayer) {
|
|
302
321
|
let size = view.getVisibleSize();
|
|
303
|
-
if (this.param.
|
|
304
|
-
this.
|
|
322
|
+
if (this.param.isVideoFit) {
|
|
323
|
+
this.videoFit({ x: size.width / 2, y: -size.height / 2, width: 1080, height: 1920 });
|
|
305
324
|
return;
|
|
306
325
|
}
|
|
307
326
|
const designResolutionSize = view.getDesignResolutionSize()
|
|
@@ -105,6 +105,8 @@ export class VideoPlayWX extends BaseVideo {
|
|
|
105
105
|
this.play()
|
|
106
106
|
}
|
|
107
107
|
this.remoteURL = name;
|
|
108
|
+
if (!param.isTargetSize)
|
|
109
|
+
this.autoSize()
|
|
108
110
|
}
|
|
109
111
|
|
|
110
112
|
play(isloop?: boolean) {
|
|
@@ -200,6 +202,30 @@ export class VideoPlayWX extends BaseVideo {
|
|
|
200
202
|
}
|
|
201
203
|
|
|
202
204
|
setSize(param: { x: number, y: number, width: number, height: number }) {
|
|
205
|
+
if (this.videoPlayer) {
|
|
206
|
+
// fill 填充,视频拉伸填满整个容器,不保证保持原有长宽比例
|
|
207
|
+
// contain 包含,保持原有长宽比例。保证视频尺寸一定可以在容器里面放得下。因此,可能会有部分空白
|
|
208
|
+
// cover 覆盖,保持原有长宽比例。保证视频尺寸一定大于容器尺寸,宽度和高度至少有一个和容器一致。因此,视频有部分会看不见
|
|
209
|
+
const windowInfo = wx.getWindowInfo();
|
|
210
|
+
const { windowWidth, windowHeight } = windowInfo;
|
|
211
|
+
const designResolutionSize = view.getDesignResolutionSize()
|
|
212
|
+
|
|
213
|
+
const ratio = windowWidth / designResolutionSize.width
|
|
214
|
+
const width = param.width * ratio
|
|
215
|
+
const height = param.height * ratio
|
|
216
|
+
const x = param.x * ratio - width / 2
|
|
217
|
+
const y = param.y * ratio + param.height / 2 * ratio;
|
|
218
|
+
this.videoPlayer.objectFit = "fill"
|
|
219
|
+
this.videoPlayer.x = x;
|
|
220
|
+
this.videoPlayer.y = windowHeight - y;
|
|
221
|
+
this.videoPlayer.width = width
|
|
222
|
+
this.videoPlayer.height = height
|
|
223
|
+
this.videoPlayer.underGameView = true;
|
|
224
|
+
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
videoFit(param: { x: number, y: number, width: number, height: number }) {
|
|
203
229
|
if (this.videoPlayer) {
|
|
204
230
|
const windowInfo = wx.getWindowInfo();
|
|
205
231
|
const { windowWidth, windowHeight } = windowInfo;
|
|
@@ -222,15 +248,17 @@ export class VideoPlayWX extends BaseVideo {
|
|
|
222
248
|
// 节点位置适配
|
|
223
249
|
autoSize() {
|
|
224
250
|
if (this.videoPlayer) {
|
|
225
|
-
if (this.param.isFullNot) {
|
|
226
|
-
this.setSize({ x: 0, y: 0, width: 1080, height: 1920 })
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
251
|
const designResolutionSize = view.getDesignResolutionSize()
|
|
230
252
|
let windowInfo = wx.getWindowInfo();
|
|
231
|
-
if (this.param.
|
|
232
|
-
|
|
253
|
+
if (this.param.isVideoFit) {
|
|
254
|
+
this.videoPlayer.objectFit = "contain";
|
|
255
|
+
this.videoPlayer.x = 0;
|
|
256
|
+
this.videoPlayer.y = 0;
|
|
257
|
+
this.videoPlayer.width = windowInfo.windowWidth;
|
|
258
|
+
this.videoPlayer.height = windowInfo.windowHeight;
|
|
259
|
+
return;
|
|
233
260
|
}
|
|
261
|
+
|
|
234
262
|
const { windowWidth, windowHeight } = windowInfo;
|
|
235
263
|
this.videoPlayer.objectFit = "cover"
|
|
236
264
|
this.videoPlayer.x = 0;
|
|
@@ -200,7 +200,7 @@ export class VideoPlayWeb extends BaseVideo {
|
|
|
200
200
|
autoSize() {
|
|
201
201
|
//const size = { width: 1080, height: 1920 }
|
|
202
202
|
let screenSize = view.getVisibleSize(); // 获取当前屏幕尺寸
|
|
203
|
-
if (this.param.
|
|
203
|
+
if (this.param.isVideoFit) {
|
|
204
204
|
screenSize = new Size(1080, 1920)
|
|
205
205
|
}
|
|
206
206
|
const designResolutionSize = view.getDesignResolutionSize()
|
|
@@ -216,7 +216,7 @@ export class VideoPlayWeb extends BaseVideo {
|
|
|
216
216
|
|
|
217
217
|
const x = width_w / 2
|
|
218
218
|
let y = 0//-height / 4
|
|
219
|
-
if (this.param.
|
|
219
|
+
if (this.param.isVideoFit) {
|
|
220
220
|
y = height_h / 2
|
|
221
221
|
}
|
|
222
222
|
|