@realsee/vreo 2.4.7 → 2.5.0-alpha.2
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/README.md +1 -1
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/Player.AudioLike.html +2 -2
- package/docs/classes/Player.Controller.html +52 -4
- package/docs/classes/Player.Player.html +43 -2
- package/docs/classes/Player.VideoAgentMesh.html +61 -4
- package/docs/classes/Player.VideoAgentScene.html +2 -2
- package/docs/demo/assets/{examples-5qw3pq5z.js → examples-DfiAz2fR.js} +1 -1
- package/docs/demo/assets/react-BnzBLum3.css +1 -0
- package/docs/demo/examples.html +1 -1
- package/docs/demo/index-react.html +2 -2
- package/docs/demo/index.html +1 -1
- package/docs/enums/Player.InfoPanelStyleEnum.html +2 -2
- package/docs/enums/Player.InfoPanelTypeEnum.html +2 -2
- package/docs/enums/Player.PanoEffectEnum.html +2 -2
- package/docs/enums/Player.PanoTagEnum.html +2 -2
- package/docs/enums/Player.PanoTagStyleEnum.html +3 -3
- package/docs/enums/Player.VreoKeyframeEnum.html +13 -13
- package/docs/enums/fivePlugins.CameraMovementEffect.html +2 -2
- package/docs/enums/fivePlugins.Rotation.html +2 -2
- package/docs/functions/custom.SpatialScenePanel.html +1 -1
- package/docs/functions/react.useVreoAction.html +8 -1
- package/docs/functions/react.useVreoEventCallback.html +10 -1
- package/docs/functions/react.useVreoPausedState.html +8 -1
- package/docs/index.html +1 -1
- package/docs/interfaces/Player.Appearance.html +2 -0
- package/docs/interfaces/Player.CustomVreoKeyframeProps.html +2 -2
- package/docs/interfaces/Player.PlayerConfigs.html +6 -6
- package/docs/interfaces/Player.Vertex.html +2 -2
- package/docs/interfaces/Player.VideoAgentMeshOptions.html +5 -4
- package/docs/interfaces/Player.VreoKeyframe.html +2 -2
- package/docs/interfaces/Player.VreoUnit.html +2 -2
- package/docs/interfaces/Player.VreoVideo.html +2 -2
- package/docs/interfaces/fivePlugins.CSS3DRenderPluginExportType.html +7 -5
- package/docs/interfaces/fivePlugins.CameraMovementOptsCallback.html +2 -2
- package/docs/interfaces/fivePlugins.CameraMovementPluginExportType.html +3 -3
- package/docs/interfaces/fivePlugins.CameraMovementPluginParameterType.html +1 -1
- package/docs/interfaces/fivePlugins.ModelTVVideoPluginData.html +2 -2
- package/docs/interfaces/fivePlugins.ModelTVVideoPluginExportType.html +2 -2
- package/docs/interfaces/fivePlugins.ModelTVVideoPluginParameterType.html +2 -2
- package/docs/interfaces/fivePlugins.Vector3Position.html +2 -2
- package/docs/interfaces/react.VreoActionCallbacks.html +7 -7
- package/docs/interfaces/react.VreoProviderProps.html +5 -2
- package/docs/modules/Player.html +1 -1
- package/docs/modules/fivePlugins.html +1 -1
- package/docs/types/Player.AppSize.html +1 -0
- package/docs/types/Player.AudioLikeEvent.html +2 -2
- package/docs/types/Player.CameraMovementData.html +1 -1
- package/docs/types/Player.CustomData.html +1 -1
- package/docs/types/Player.InfoPanelData.html +2 -2
- package/docs/types/Player.ModelVideoData.html +5 -5
- package/docs/types/Player.PanoEffectData.html +2 -2
- package/docs/types/Player.PanoTagData.html +2 -2
- package/docs/types/Player.PanoTextLabelData.html +2 -2
- package/docs/types/Player.PrompterData.html +2 -2
- package/docs/types/Player.QuadrangleVertexs.html +1 -1
- package/docs/types/Player.Quaternion.html +2 -2
- package/docs/types/Player.UpdateVRPanoramaData.html +2 -2
- package/docs/types/Player.Vertexs.html +1 -1
- package/docs/types/Player.VideoEffectData.html +2 -2
- package/docs/types/Player.VreoKeyframeEvent.html +1 -1
- package/docs/types/Player.VreoKeyframeMap.html +2 -2
- package/docs/types/Player.VreoSubscribe.html +1 -1
- package/docs/types/Player.WaveAppearance.html +1 -0
- package/docs/types/fivePlugins.CSS3DRenderPluginParameterType.html +1 -0
- package/docs/types/fivePlugins.MoveArgs.html +1 -1
- package/docs/types/fivePlugins.MoveOpts.html +1 -1
- package/docs/types/fivePlugins.RotateArgs.html +1 -1
- package/docs/types/fivePlugins.RotateOpts.html +1 -1
- package/docs/variables/fivePlugins.CSS3DRenderPlugin.html +2 -2
- package/docs/variables/fivePlugins.CameraMovementPlugin.html +1 -1
- package/docs/variables/fivePlugins.ModelTVVideoPlugin.html +1 -1
- package/docs/variables/react.VreoProvider.html +9 -1
- package/lib/PlayController/createHTMLAudioElement.js +5 -12
- package/lib/PlayController/index.js +27 -34
- package/lib/Player/App.js +25 -34
- package/lib/Player/Controller.d.ts +106 -2
- package/lib/Player/Controller.js +190 -78
- package/lib/Player/custom/SpatialScenePanel/index.js +20 -31
- package/lib/Player/hooks.js +6 -15
- package/lib/Player/index.d.ts +103 -0
- package/lib/Player/index.js +153 -45
- package/lib/Player/modules/Drawer/index.js +8 -17
- package/lib/Player/modules/PopUp/index.js +8 -17
- package/lib/Player/modules/ResizeObserver/index.js +10 -17
- package/lib/Player/modules/VideoAgent/VideoAgentMesh.d.ts +108 -7
- package/lib/Player/modules/VideoAgent/VideoAgentMesh.js +157 -52
- package/lib/Player/modules/VideoAgent/VideoAgentScene.js +16 -25
- package/lib/Player/modules/VideoAgent/index.js +8 -17
- package/lib/Player/modules/Wave/index.js +24 -33
- package/lib/Player/modules/keyframes/BgMusic/index.js +13 -22
- package/lib/Player/modules/keyframes/CameraMovement/index.js +17 -26
- package/lib/Player/modules/keyframes/InfoPanel/index.js +13 -21
- package/lib/Player/modules/keyframes/ModelVideo/index.js +17 -26
- package/lib/Player/modules/keyframes/PanoEffect/index.js +21 -30
- package/lib/Player/modules/keyframes/PanoEffect/lineAnime.js +6 -14
- package/lib/Player/modules/keyframes/PanoTag/index.js +10 -18
- package/lib/Player/modules/keyframes/PanoTextLabel/index.js +19 -28
- package/lib/Player/modules/keyframes/Prompter/index.js +13 -22
- package/lib/Player/modules/keyframes/UpdateVRPanorama/index.js +16 -24
- package/lib/Player/modules/keyframes/VideoEffect/index.js +18 -28
- package/lib/Player/typings.js +1 -5
- package/lib/fivePlugins/CSS3DRenderPlugin/centerPoint.js +3 -9
- package/lib/fivePlugins/CSS3DRenderPlugin/createResizeObserver.js +1 -7
- package/lib/fivePlugins/CSS3DRenderPlugin/evenNumber.js +1 -7
- package/lib/fivePlugins/CSS3DRenderPlugin/index.d.ts +6 -12
- package/lib/fivePlugins/CSS3DRenderPlugin/index.js +27 -37
- package/lib/fivePlugins/CSS3DRenderPlugin/transformPositionToVector3.js +3 -9
- package/lib/fivePlugins/CameraMovementPlugin/index.js +15 -22
- package/lib/fivePlugins/CameraMovementPlugin/typings.js +6 -10
- package/lib/fivePlugins/ModelTVVideoPlugin/index.js +9 -18
- package/lib/index.js +1 -12
- package/lib/react/index.d.ts +111 -0
- package/lib/react/index.js +148 -24
- package/lib/shared-utils/Audio.js +27 -37
- package/lib/shared-utils/AudioLike.js +22 -29
- package/lib/shared-utils/Preloader.js +1 -7
- package/lib/shared-utils/addResizeListener.js +4 -11
- package/lib/shared-utils/animationFrame/BetterTween.js +23 -33
- package/lib/shared-utils/animationFrame/index.js +4 -13
- package/lib/shared-utils/animationFrame/tween.js +9 -17
- package/lib/shared-utils/createTransMatrix.js +5 -14
- package/lib/shared-utils/getFileExpandedName.js +1 -7
- package/lib/shared-utils/getMediaInfo.js +8 -19
- package/lib/shared-utils/setElementDataset.js +1 -7
- package/lib/typings/VreoUnit.js +15 -17
- package/package.json +58 -5
- package/stylesheets/custom/SpatialScenePanel.css +7 -7
- package/stylesheets/default.css +1 -1
- package/docs/demo/assets/react-dPVEotm3.css +0 -1
- /package/docs/demo/assets/{react-BLZb_LNZ.js → react-C4h9qndP.js} +0 -0
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
import AudioLike from '../../../shared-utils/AudioLike';
|
|
3
|
+
/**
|
|
4
|
+
* 视频经纪人贴片的配置选项
|
|
5
|
+
*/
|
|
3
6
|
export interface VideoAgentMeshOptions {
|
|
4
7
|
/**
|
|
5
8
|
* 自定义视频实例。
|
|
@@ -17,31 +20,129 @@ export interface VideoAgentMeshOptions {
|
|
|
17
20
|
preload?: boolean;
|
|
18
21
|
}
|
|
19
22
|
/**
|
|
20
|
-
*
|
|
23
|
+
* 视频经纪人贴片类
|
|
24
|
+
*
|
|
25
|
+
* 基于 THREE.js 的网格对象,作为 VR 视频播放的核心媒体管理组件。
|
|
26
|
+
* 负责视频和音频的播放控制、时间同步、绿幕抠图渲染等功能。
|
|
27
|
+
*
|
|
28
|
+
* 主要特性:
|
|
29
|
+
* - 支持绿幕抠图渲染(ChromaKey)
|
|
30
|
+
* - 音视频同步播放管理
|
|
31
|
+
* - 媒体预载优化策略
|
|
32
|
+
* - 跨平台播放兼容性
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const videoMesh = new VideoAgentMesh(1920, 1080, 32, 18, {
|
|
37
|
+
* preload: true,
|
|
38
|
+
* videoInstance: customVideoElement
|
|
39
|
+
* })
|
|
40
|
+
*
|
|
41
|
+
* // 播放视频
|
|
42
|
+
* await videoMesh.play('https://example.com/video.mp4', 0, 60)
|
|
43
|
+
*
|
|
44
|
+
* // 获取当前时间
|
|
45
|
+
* console.log(videoMesh.currentTime)
|
|
46
|
+
*
|
|
47
|
+
* // 销毁资源
|
|
48
|
+
* videoMesh.dispose()
|
|
49
|
+
* ```
|
|
21
50
|
*/
|
|
22
51
|
export declare class VideoAgentMesh extends THREE.Mesh {
|
|
52
|
+
/** 配置选项 */
|
|
23
53
|
options: VideoAgentMeshOptions;
|
|
54
|
+
/** 当前视频URL */
|
|
24
55
|
videoUrl?: string;
|
|
56
|
+
/** 是否冻结状态 */
|
|
25
57
|
freeze: boolean;
|
|
58
|
+
/** 是否暂停状态 */
|
|
26
59
|
paused: boolean;
|
|
60
|
+
/** 音频实例 */
|
|
27
61
|
audioInstance: HTMLAudioElement;
|
|
62
|
+
/** AudioLike 实例 */
|
|
28
63
|
audioLikeInstance: AudioLike;
|
|
64
|
+
/** 移除事件监听器的函数 */
|
|
29
65
|
$removeEventListener: () => void;
|
|
66
|
+
/**
|
|
67
|
+
* 获取当前的媒体实例
|
|
68
|
+
*
|
|
69
|
+
* 根据媒体类型自动返回对应的播放实例:
|
|
70
|
+
* - 无媒体时返回 AudioLike 实例
|
|
71
|
+
* - 音频文件返回 HTMLAudioElement
|
|
72
|
+
* - 视频文件返回 HTMLVideoElement
|
|
73
|
+
*
|
|
74
|
+
* @returns 当前活跃的媒体播放实例
|
|
75
|
+
*/
|
|
30
76
|
get mediaInstance(): HTMLAudioElement | HTMLVideoElement | AudioLike;
|
|
31
77
|
/**
|
|
78
|
+
* 创建视频经纪人贴片实例
|
|
32
79
|
*
|
|
33
|
-
* @param width
|
|
34
|
-
* @param height
|
|
35
|
-
* @param widthSegments
|
|
36
|
-
* @param heightSegments
|
|
37
|
-
* @param options
|
|
80
|
+
* @param width - 网格宽度
|
|
81
|
+
* @param height - 网格高度
|
|
82
|
+
* @param widthSegments - 宽度方向分段数
|
|
83
|
+
* @param heightSegments - 高度方向分段数
|
|
84
|
+
* @param options - 配置选项
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const mesh = new VideoAgentMesh(1920, 1080, 32, 18, {
|
|
89
|
+
* preload: true,
|
|
90
|
+
* videoInstance: document.getElementById('video')
|
|
91
|
+
* })
|
|
92
|
+
* ```
|
|
38
93
|
*/
|
|
39
94
|
constructor(width: number, height: number, widthSegments: number, heightSegments: number, options?: VideoAgentMeshOptions);
|
|
95
|
+
/**
|
|
96
|
+
* 更新媒体资源
|
|
97
|
+
*
|
|
98
|
+
* 内部方法,负责加载新的视频/音频资源,处理预载逻辑和着色器设置
|
|
99
|
+
* @param videoUrl - 媒体文件URL
|
|
100
|
+
* @private
|
|
101
|
+
*/
|
|
40
102
|
private update;
|
|
103
|
+
/**
|
|
104
|
+
* 播放媒体内容
|
|
105
|
+
*
|
|
106
|
+
* 支持多种播放模式:
|
|
107
|
+
* - 播放指定视频/音频文件
|
|
108
|
+
* - 仅设置时长(无媒体文件)
|
|
109
|
+
* - 继续播放当前媒体
|
|
110
|
+
*
|
|
111
|
+
* @param videoUrl - 媒体文件URL,默认为空字符串
|
|
112
|
+
* @param currentTime - 播放起始时间(秒),默认为 0
|
|
113
|
+
* @param duration - 媒体总时长(秒),可选
|
|
114
|
+
* @returns Promise<boolean> 播放是否成功
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* // 播放视频文件
|
|
119
|
+
* await mesh.play('video.mp4', 10, 120)
|
|
120
|
+
*
|
|
121
|
+
* // 仅设置时长(音频跟踪)
|
|
122
|
+
* await mesh.play('', 0, 60)
|
|
123
|
+
*
|
|
124
|
+
* // 继续播放当前媒体
|
|
125
|
+
* await mesh.play()
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
41
128
|
play(videoUrl?: string, currentTime?: number, duration?: number): Promise<unknown>;
|
|
42
129
|
/**
|
|
43
|
-
*
|
|
130
|
+
* 获取当前播放时间(毫秒)
|
|
131
|
+
*
|
|
132
|
+
* 将媒体实例的秒级时间转换为毫秒,提供更高精度的时间控制
|
|
133
|
+
* @returns 当前播放时间戳(毫秒)
|
|
44
134
|
*/
|
|
45
135
|
get currentTime(): number;
|
|
136
|
+
/**
|
|
137
|
+
* 销毁视频经纪人贴片实例
|
|
138
|
+
*
|
|
139
|
+
* 清理所有事件监听器、DOM元素和缓存实例,释放内存资源
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```typescript
|
|
143
|
+
* // 在组件卸载时调用
|
|
144
|
+
* videoMesh.dispose()
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
46
147
|
dispose(): void;
|
|
47
148
|
}
|
|
@@ -1,45 +1,76 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
12
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
-
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
14
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
15
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
16
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
17
|
-
var THREE = _interopRequireWildcard(require("three"));
|
|
18
|
-
var _Preloader = require("../../../shared-utils/Preloader");
|
|
19
|
-
var _mobx = require("mobx");
|
|
20
|
-
var _AudioLike = _interopRequireDefault(require("../../../shared-utils/AudioLike"));
|
|
21
|
-
var _getMediaInfo = require("../../../shared-utils/getMediaInfo");
|
|
22
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) { "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); } return f; })(e, t); }
|
|
23
|
-
function _createSuper(t) { var r = _isNativeReflectConstruct(); return function () { var e, o = (0, _getPrototypeOf2["default"])(t); if (r) { var s = (0, _getPrototypeOf2["default"])(this).constructor; e = Reflect.construct(o, arguments, s); } else e = o.apply(this, arguments); return (0, _possibleConstructorReturn2["default"])(this, e); }; }
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
4
|
+
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
|
|
5
|
+
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
6
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
|
|
7
|
+
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
|
|
8
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
9
|
+
function _createSuper(t) { var r = _isNativeReflectConstruct(); return function () { var e, o = _getPrototypeOf(t); if (r) { var s = _getPrototypeOf(this).constructor; e = Reflect.construct(o, arguments, s); } else e = o.apply(this, arguments); return _possibleConstructorReturn(this, e); }; }
|
|
24
10
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
11
|
+
import * as THREE from 'three';
|
|
12
|
+
import { Preloader } from "../../../shared-utils/Preloader.js";
|
|
13
|
+
import { makeObservable, observable, runInAction } from 'mobx';
|
|
14
|
+
import AudioLike from "../../../shared-utils/AudioLike.js";
|
|
15
|
+
import { getMediaType } from "../../../shared-utils/getMediaInfo.js";
|
|
25
16
|
var vertexShader = "\nvarying vec2 vUv;\nvarying vec2 vColorUv;\nvarying vec2 vMaskUv;\nvoid main(){\n vUv = uv;\n vColorUv = vec2(uv.x / 2.0, uv.y);\n vMaskUv = vec2(0.5 + uv.x / 2.0, uv.y);\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}\n";
|
|
26
17
|
var fragmentShaderTpl = function fragmentShaderTpl() {
|
|
27
18
|
return "\nuniform int enable;\nuniform sampler2D map;\nvarying vec2 vUv;\nvarying vec2 vColorUv;\nvarying vec2 vMaskUv;\n\nvec3 hsv2rgb(vec3 c) {\n const vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n\nvec3 rgb2hsv(vec3 c) {\n const vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n\n float d = q.x - min(q.w, q.y);\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + 0.001)), d / (q.x + 0.001), q.x);\n}\n\nvoid main(void) {\n vec3 color = texture2D(map, vUv).xyz;\n float amask = 1.0;\n\n float ref = color.r;\n if (ref < color.b) ref = color.b;\n amask = color.g - ref + 0.1;\n amask = smoothstep(0.1, 0.3, amask);\n amask = 1.0 - amask;\n\n vec3 target = rgb2hsv(vec3(0.0 / 255.0, 255.0 / 255.0, 0.0 / 255.0));\n vec3 hsv = rgb2hsv(color);\n float distance = abs(hsv.x - target.x);\n if (distance < 0.15) {\n hsv.y = 0.0;\n }\n color = hsv2rgb(hsv);\n\n gl_FragColor = vec4(color.rgb, amask * float(enable));\n}\n";
|
|
28
19
|
};
|
|
29
20
|
var cacheInstance = {};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 视频经纪人贴片的配置选项
|
|
24
|
+
*/
|
|
25
|
+
|
|
30
26
|
/**
|
|
31
|
-
*
|
|
27
|
+
* 视频经纪人贴片类
|
|
28
|
+
*
|
|
29
|
+
* 基于 THREE.js 的网格对象,作为 VR 视频播放的核心媒体管理组件。
|
|
30
|
+
* 负责视频和音频的播放控制、时间同步、绿幕抠图渲染等功能。
|
|
31
|
+
*
|
|
32
|
+
* 主要特性:
|
|
33
|
+
* - 支持绿幕抠图渲染(ChromaKey)
|
|
34
|
+
* - 音视频同步播放管理
|
|
35
|
+
* - 媒体预载优化策略
|
|
36
|
+
* - 跨平台播放兼容性
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const videoMesh = new VideoAgentMesh(1920, 1080, 32, 18, {
|
|
41
|
+
* preload: true,
|
|
42
|
+
* videoInstance: customVideoElement
|
|
43
|
+
* })
|
|
44
|
+
*
|
|
45
|
+
* // 播放视频
|
|
46
|
+
* await videoMesh.play('https://example.com/video.mp4', 0, 60)
|
|
47
|
+
*
|
|
48
|
+
* // 获取当前时间
|
|
49
|
+
* console.log(videoMesh.currentTime)
|
|
50
|
+
*
|
|
51
|
+
* // 销毁资源
|
|
52
|
+
* videoMesh.dispose()
|
|
53
|
+
* ```
|
|
32
54
|
*/
|
|
33
|
-
var VideoAgentMesh =
|
|
34
|
-
(
|
|
55
|
+
export var VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh) {
|
|
56
|
+
_inherits(VideoAgentMesh, _THREE$Mesh);
|
|
35
57
|
var _super = _createSuper(VideoAgentMesh);
|
|
36
58
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* @param
|
|
40
|
-
* @param
|
|
41
|
-
* @param
|
|
42
|
-
* @param
|
|
59
|
+
* 创建视频经纪人贴片实例
|
|
60
|
+
*
|
|
61
|
+
* @param width - 网格宽度
|
|
62
|
+
* @param height - 网格高度
|
|
63
|
+
* @param widthSegments - 宽度方向分段数
|
|
64
|
+
* @param heightSegments - 高度方向分段数
|
|
65
|
+
* @param options - 配置选项
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const mesh = new VideoAgentMesh(1920, 1080, 32, 18, {
|
|
70
|
+
* preload: true,
|
|
71
|
+
* videoInstance: document.getElementById('video')
|
|
72
|
+
* })
|
|
73
|
+
* ```
|
|
43
74
|
*/
|
|
44
75
|
function VideoAgentMesh(width, height, widthSegments, heightSegments) {
|
|
45
76
|
var _this$options$videoIn, _this$options$videoIn2;
|
|
@@ -47,7 +78,7 @@ var VideoAgentMesh = exports.VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh
|
|
|
47
78
|
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
|
|
48
79
|
preload: true
|
|
49
80
|
};
|
|
50
|
-
(
|
|
81
|
+
_classCallCheck(this, VideoAgentMesh);
|
|
51
82
|
if (!options.videoInstance) {
|
|
52
83
|
if (cacheInstance.videoInstance) {
|
|
53
84
|
options.videoInstance = cacheInstance.videoInstance;
|
|
@@ -99,12 +130,12 @@ var VideoAgentMesh = exports.VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh
|
|
|
99
130
|
} else {
|
|
100
131
|
_this.audioInstance = options.audioInstance;
|
|
101
132
|
}
|
|
102
|
-
_this.audioLikeInstance = new
|
|
103
|
-
|
|
104
|
-
paused:
|
|
133
|
+
_this.audioLikeInstance = new AudioLike();
|
|
134
|
+
makeObservable(_assertThisInitialized(_this), {
|
|
135
|
+
paused: observable
|
|
105
136
|
});
|
|
106
137
|
var updatePaused = function updatePaused(paused) {
|
|
107
|
-
return
|
|
138
|
+
return runInAction(function () {
|
|
108
139
|
return _this.paused = paused;
|
|
109
140
|
});
|
|
110
141
|
};
|
|
@@ -131,13 +162,45 @@ var VideoAgentMesh = exports.VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh
|
|
|
131
162
|
};
|
|
132
163
|
return _this;
|
|
133
164
|
}
|
|
134
|
-
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* 更新媒体资源
|
|
168
|
+
*
|
|
169
|
+
* 内部方法,负责加载新的视频/音频资源,处理预载逻辑和着色器设置
|
|
170
|
+
* @param videoUrl - 媒体文件URL
|
|
171
|
+
* @private
|
|
172
|
+
*/
|
|
173
|
+
_createClass(VideoAgentMesh, [{
|
|
135
174
|
key: "mediaInstance",
|
|
136
|
-
get:
|
|
175
|
+
get: /** 配置选项 */
|
|
176
|
+
|
|
177
|
+
/** 当前视频URL */
|
|
178
|
+
|
|
179
|
+
/** 是否冻结状态 */
|
|
180
|
+
|
|
181
|
+
/** 是否暂停状态 */
|
|
182
|
+
|
|
183
|
+
/** 音频实例 */
|
|
184
|
+
|
|
185
|
+
/** AudioLike 实例 */
|
|
186
|
+
|
|
187
|
+
/** 移除事件监听器的函数 */
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* 获取当前的媒体实例
|
|
191
|
+
*
|
|
192
|
+
* 根据媒体类型自动返回对应的播放实例:
|
|
193
|
+
* - 无媒体时返回 AudioLike 实例
|
|
194
|
+
* - 音频文件返回 HTMLAudioElement
|
|
195
|
+
* - 视频文件返回 HTMLVideoElement
|
|
196
|
+
*
|
|
197
|
+
* @returns 当前活跃的媒体播放实例
|
|
198
|
+
*/
|
|
199
|
+
function get() {
|
|
137
200
|
if (!this.videoUrl) {
|
|
138
201
|
return this.audioLikeInstance;
|
|
139
202
|
}
|
|
140
|
-
if (
|
|
203
|
+
if (getMediaType(this.videoUrl) === 'audio') {
|
|
141
204
|
return this.audioInstance;
|
|
142
205
|
}
|
|
143
206
|
var uniforms = this.material.uniforms;
|
|
@@ -146,11 +209,11 @@ var VideoAgentMesh = exports.VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh
|
|
|
146
209
|
}
|
|
147
210
|
}, {
|
|
148
211
|
key: "update",
|
|
149
|
-
value: function () {
|
|
150
|
-
var _update = (
|
|
212
|
+
value: (function () {
|
|
213
|
+
var _update = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(videoUrl) {
|
|
151
214
|
var _this2 = this;
|
|
152
215
|
var uniforms, onStart;
|
|
153
|
-
return
|
|
216
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
154
217
|
while (1) {
|
|
155
218
|
switch (_context.prev = _context.next) {
|
|
156
219
|
case 0:
|
|
@@ -175,13 +238,13 @@ var VideoAgentMesh = exports.VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh
|
|
|
175
238
|
case 6:
|
|
176
239
|
uniforms = this.material.uniforms;
|
|
177
240
|
this.mediaInstance.muted = true;
|
|
178
|
-
if (!(this.options.preload || this.options.preload === undefined ||
|
|
241
|
+
if (!(this.options.preload || this.options.preload === undefined || getMediaType(this.videoUrl) === 'video')) {
|
|
179
242
|
_context.next = 18;
|
|
180
243
|
break;
|
|
181
244
|
}
|
|
182
245
|
_context.t1 = URL;
|
|
183
246
|
_context.next = 12;
|
|
184
|
-
return
|
|
247
|
+
return Preloader.blob(this.videoUrl);
|
|
185
248
|
case 12:
|
|
186
249
|
_context.t2 = _context.sent;
|
|
187
250
|
_context.next = 15;
|
|
@@ -199,7 +262,7 @@ var VideoAgentMesh = exports.VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh
|
|
|
199
262
|
if (_this2.mediaInstance.currentTime === 0) return;
|
|
200
263
|
_this2.freeze = false;
|
|
201
264
|
_this2.mediaInstance.muted = false;
|
|
202
|
-
uniforms.enable.value =
|
|
265
|
+
uniforms.enable.value = getMediaType(_this2.videoUrl) ? 1 : 0;
|
|
203
266
|
_this2.mediaInstance.removeEventListener('timeupdate', onStart, false);
|
|
204
267
|
};
|
|
205
268
|
this.mediaInstance.addEventListener('timeupdate', onStart, false);
|
|
@@ -215,16 +278,42 @@ var VideoAgentMesh = exports.VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh
|
|
|
215
278
|
}
|
|
216
279
|
return update;
|
|
217
280
|
}()
|
|
281
|
+
/**
|
|
282
|
+
* 播放媒体内容
|
|
283
|
+
*
|
|
284
|
+
* 支持多种播放模式:
|
|
285
|
+
* - 播放指定视频/音频文件
|
|
286
|
+
* - 仅设置时长(无媒体文件)
|
|
287
|
+
* - 继续播放当前媒体
|
|
288
|
+
*
|
|
289
|
+
* @param videoUrl - 媒体文件URL,默认为空字符串
|
|
290
|
+
* @param currentTime - 播放起始时间(秒),默认为 0
|
|
291
|
+
* @param duration - 媒体总时长(秒),可选
|
|
292
|
+
* @returns Promise<boolean> 播放是否成功
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* ```typescript
|
|
296
|
+
* // 播放视频文件
|
|
297
|
+
* await mesh.play('video.mp4', 10, 120)
|
|
298
|
+
*
|
|
299
|
+
* // 仅设置时长(音频跟踪)
|
|
300
|
+
* await mesh.play('', 0, 60)
|
|
301
|
+
*
|
|
302
|
+
* // 继续播放当前媒体
|
|
303
|
+
* await mesh.play()
|
|
304
|
+
* ```
|
|
305
|
+
*/
|
|
306
|
+
)
|
|
218
307
|
}, {
|
|
219
308
|
key: "play",
|
|
220
|
-
value: function () {
|
|
221
|
-
var _play = (
|
|
309
|
+
value: (function () {
|
|
310
|
+
var _play = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
222
311
|
var _this3 = this;
|
|
223
312
|
var videoUrl,
|
|
224
313
|
currentTime,
|
|
225
314
|
duration,
|
|
226
315
|
_args3 = arguments;
|
|
227
|
-
return
|
|
316
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
228
317
|
while (1) {
|
|
229
318
|
switch (_context3.prev = _context3.next) {
|
|
230
319
|
case 0:
|
|
@@ -278,8 +367,8 @@ var VideoAgentMesh = exports.VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh
|
|
|
278
367
|
this.mediaInstance.pause();
|
|
279
368
|
_context3.next = 28;
|
|
280
369
|
return new Promise(function (resolve) {
|
|
281
|
-
return setTimeout(/*#__PURE__*/(
|
|
282
|
-
return
|
|
370
|
+
return setTimeout(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
371
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
283
372
|
while (1) {
|
|
284
373
|
switch (_context2.prev = _context2.next) {
|
|
285
374
|
case 0:
|
|
@@ -311,13 +400,29 @@ var VideoAgentMesh = exports.VideoAgentMesh = /*#__PURE__*/function (_THREE$Mesh
|
|
|
311
400
|
return play;
|
|
312
401
|
}()
|
|
313
402
|
/**
|
|
314
|
-
*
|
|
403
|
+
* 获取当前播放时间(毫秒)
|
|
404
|
+
*
|
|
405
|
+
* 将媒体实例的秒级时间转换为毫秒,提供更高精度的时间控制
|
|
406
|
+
* @returns 当前播放时间戳(毫秒)
|
|
315
407
|
*/
|
|
408
|
+
)
|
|
316
409
|
}, {
|
|
317
410
|
key: "currentTime",
|
|
318
411
|
get: function get() {
|
|
319
412
|
return this.mediaInstance.currentTime * 1000;
|
|
320
413
|
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* 销毁视频经纪人贴片实例
|
|
417
|
+
*
|
|
418
|
+
* 清理所有事件监听器、DOM元素和缓存实例,释放内存资源
|
|
419
|
+
*
|
|
420
|
+
* @example
|
|
421
|
+
* ```typescript
|
|
422
|
+
* // 在组件卸载时调用
|
|
423
|
+
* videoMesh.dispose()
|
|
424
|
+
* ```
|
|
425
|
+
*/
|
|
321
426
|
}, {
|
|
322
427
|
key: "dispose",
|
|
323
428
|
value: function dispose() {
|
|
@@ -1,42 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
exports.VideoAgentScene = void 0;
|
|
9
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
12
|
-
var THREE = _interopRequireWildcard(require("three"));
|
|
13
|
-
var _addResizeListener = require("../../../shared-utils/addResizeListener");
|
|
14
|
-
var _VideoAgentMesh = require("./VideoAgentMesh");
|
|
15
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) { "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); } return f; })(e, t); }
|
|
16
|
-
var VideoAgentScene = exports.VideoAgentScene = /*#__PURE__*/(0, _createClass2["default"])(function VideoAgentScene(container, options) {
|
|
1
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
4
|
+
import * as THREE from 'three';
|
|
5
|
+
import { addResizeListener } from "../../../shared-utils/addResizeListener.js";
|
|
6
|
+
import { VideoAgentMesh } from "./VideoAgentMesh.js";
|
|
7
|
+
export var VideoAgentScene = /*#__PURE__*/_createClass(function VideoAgentScene(container, options) {
|
|
17
8
|
var _this = this;
|
|
18
|
-
(
|
|
19
|
-
(
|
|
20
|
-
(
|
|
21
|
-
(
|
|
9
|
+
_classCallCheck(this, VideoAgentScene);
|
|
10
|
+
_defineProperty(this, "scene", new THREE.Scene());
|
|
11
|
+
_defineProperty(this, "camera", new THREE.OrthographicCamera(-240, 240, 135, -135));
|
|
12
|
+
_defineProperty(this, "renderer", new THREE.WebGLRenderer({
|
|
22
13
|
alpha: true
|
|
23
14
|
}));
|
|
24
|
-
(
|
|
25
|
-
(
|
|
15
|
+
_defineProperty(this, "disposers", []);
|
|
16
|
+
_defineProperty(this, "run", function () {
|
|
26
17
|
// 视频开始 1s 不渲染:规避某些设备黑屏闪烁问题。视频前 2s 是最好是静默的。
|
|
27
18
|
if (!(_this.videoAgentMesh.paused || _this.videoAgentMesh.freeze) && _this.videoAgentMesh.currentTime > 1000) {
|
|
28
19
|
_this.renderer.render(_this.scene, _this.camera);
|
|
29
20
|
}
|
|
30
21
|
requestAnimationFrame(_this.run);
|
|
31
22
|
});
|
|
32
|
-
(
|
|
23
|
+
_defineProperty(this, "dispose", function () {
|
|
33
24
|
var _this$videoAgentMesh;
|
|
34
25
|
(_this$videoAgentMesh = _this.videoAgentMesh) === null || _this$videoAgentMesh === void 0 ? void 0 : _this$videoAgentMesh.dispose();
|
|
35
26
|
_this.disposers.forEach(function (disposer) {
|
|
36
27
|
return disposer === null || disposer === void 0 ? void 0 : disposer();
|
|
37
28
|
});
|
|
38
29
|
});
|
|
39
|
-
this.videoAgentMesh = new
|
|
30
|
+
this.videoAgentMesh = new VideoAgentMesh(480, 270, 1, 1, options);
|
|
40
31
|
|
|
41
32
|
// const needRender = getMediaType(this.videoAgentMesh.videoUrl) === 'video'
|
|
42
33
|
|
|
@@ -45,7 +36,7 @@ var VideoAgentScene = exports.VideoAgentScene = /*#__PURE__*/(0, _createClass2["
|
|
|
45
36
|
this.camera.lookAt(0, 0, 0);
|
|
46
37
|
var domElement = this.renderer.domElement;
|
|
47
38
|
domElement.classList.add('VideoAgent-canvas');
|
|
48
|
-
var dispose =
|
|
39
|
+
var dispose = addResizeListener(container, function (width, height) {
|
|
49
40
|
_this.renderer.setSize(width * window.devicePixelRatio, height * window.devicePixelRatio);
|
|
50
41
|
domElement.style.width = "".concat(width, "px");
|
|
51
42
|
domElement.style.height = "".concat(height, "px");
|
|
@@ -1,20 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.VideoAgent = VideoAgent;
|
|
9
|
-
var React = _interopRequireWildcard(require("react"));
|
|
10
|
-
var _hooks = require("../../hooks");
|
|
11
|
-
var _VideoAgentScene = require("./VideoAgentScene");
|
|
12
|
-
var _classnames = _interopRequireDefault(require("classnames"));
|
|
13
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) { "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); } return f; })(e, t); }
|
|
14
|
-
function VideoAgent(props) {
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useController } from "../../hooks.js";
|
|
3
|
+
import { VideoAgentScene } from "./VideoAgentScene.js";
|
|
4
|
+
import classNames from 'classnames';
|
|
5
|
+
export function VideoAgent(props) {
|
|
15
6
|
var _controller$avatar2;
|
|
16
7
|
var ref = React.useRef(null);
|
|
17
|
-
var controller =
|
|
8
|
+
var controller = useController();
|
|
18
9
|
var showAvatar = React.useMemo(function () {
|
|
19
10
|
var _controller$avatar;
|
|
20
11
|
return ((_controller$avatar = controller.avatar) === null || _controller$avatar === void 0 ? void 0 : _controller$avatar.url) && controller.avatar.force === true;
|
|
@@ -30,7 +21,7 @@ function VideoAgent(props) {
|
|
|
30
21
|
console.warn('VideoAgentScene" 重复初始化,已被过滤');
|
|
31
22
|
return;
|
|
32
23
|
}
|
|
33
|
-
var videoAgentScene = new
|
|
24
|
+
var videoAgentScene = new VideoAgentScene(ref.current, props.options);
|
|
34
25
|
controller.videoAgentScene = videoAgentScene;
|
|
35
26
|
return function () {
|
|
36
27
|
var _controller$videoAgen2;
|
|
@@ -53,7 +44,7 @@ function VideoAgent(props) {
|
|
|
53
44
|
return (_props$onClick = props.onClick) === null || _props$onClick === void 0 ? void 0 : _props$onClick.call(props);
|
|
54
45
|
}
|
|
55
46
|
}))), /*#__PURE__*/React.createElement("div", {
|
|
56
|
-
className: (
|
|
47
|
+
className: classNames('VideoAgent', {
|
|
57
48
|
hide: !showVideoAgent
|
|
58
49
|
})
|
|
59
50
|
}, /*#__PURE__*/React.createElement("div", {
|